Next
Cowboy User Guide
Table of Contents
I. Rationale
1. The modern Web
1.1. HTTP/2
1.2. HTTP/1.1
1.3. Websocket
1.4. Long-lived requests
1.5. REST
2. Erlang and the Web
2.1. The Web is concurrent
2.2. The Web is soft real time
2.3. The Web is asynchronous
2.4. The Web is omnipresent
2.5. Learn Erlang
3. Security model
II. Introduction
4. Introduction
4.1. Prerequisites
4.2. Supported platforms
4.3. License
4.4. Versioning
4.5. Conventions
5. Getting started
5.1. Prerequisites
5.2. Bootstrap
5.3. Cowboy setup
5.4. Listening for connections
5.5. Handling requests
6. Flow diagram
6.1. Overview
6.2. Protocol-specific headers
6.3. Number of processes per connection
6.4. Date header
6.5. Binaries
III. Configuration
7. Listeners
7.1. Clear TCP listener
7.2. Secure TLS listener
7.3. Stopping the listener
7.4. Protocol configuration
8. Routing
8.1. Syntax
8.2. Match syntax
8.3. Constraints
8.4. Compilation
8.5. Using persistent_term
8.6. Live update
9. Constraints
9.1. Syntax
9.2. Built-in constraints
9.3. Custom constraints
IV. Handlers
10. Handlers
10.1. Plain HTTP handlers
10.2. Other handlers
10.3. Cleaning up
11. Loop handlers
11.1. Initialization
11.2. Receive loop
11.3. Streaming loop
11.4. Cleaning up
11.5. Hibernate
11.6. Idle timeout
12. Static files
12.1. Serve one file
12.2. Serve all files from a directory
12.3. Customize the mimetype detection
12.4. Generate an etag
V. Request and response
13. The Req object
13.1. Direct access
13.2. Introduction to the cowboy_req interface
13.3. Request method
13.4. HTTP version
13.5. Effective request URI
13.6. Bindings
13.7. Query parameters
13.8. Headers
13.9. Peer
14. Reading the request body
14.1. Request body presence
14.2. Request body length
14.3. Reading the body
14.4. Streaming the body
14.5. Reading a form urlencoded body
15. Sending a response
15.1. Reply
15.2. Stream reply
15.3. Preset response headers
15.4. Overriding headers
15.5. Preset response body
15.6. Sending files
15.7. Informational responses
15.8. Push
16. Using cookies
16.1. Setting cookies
16.2. Reading cookies
17. Multipart requests
17.1. Form-data
17.2. Checking for multipart messages
17.3. Reading a multipart message
17.4. Skipping unwanted parts
VI. REST
18. REST principles
18.1. REST architecture
18.2. Resources and resource identifiers
18.3. Resource representations
18.4. Self-descriptive messages
18.5. Hypermedia as the engine of application state
19. REST handlers
19.1. Initialization
19.2. Methods
19.3. Callbacks
19.4. Meta data
19.5. Response headers
20. REST flowcharts
20.1. Start
20.2. OPTIONS method
20.3. Content negotiation
20.4. GET and HEAD methods
20.5. PUT, POST and PATCH methods
20.6. DELETE method
20.7. Conditional requests
21. Designing a resource handler
21.1. The service
21.2. Type of resource handler
21.3. Collection handler
21.4. Single resource handler
21.5. The resource
21.6. Representations
21.7. Redirections
21.8. The request
21.9. OPTIONS method
21.10. GET and HEAD methods
21.11. PUT, POST and PATCH methods
21.12. DELETE methods
VII. Websocket
22. The Websocket protocol
22.1. Description
22.2. Websocket vs HTTP/2
22.3. Implementation
23. Websocket handlers
23.1. Upgrade
23.2. Subprotocol
23.3. Post-upgrade initialization
23.4. Receiving frames
23.5. Receiving Erlang messages
23.6. Sending frames
23.7. Keeping the connection alive
23.8. Limiting frame sizes
23.9. Saving memory
23.10. Closing the connection
VIII. Advanced
24. Streams
24.1. Stream handlers
24.2. Built-in handlers
25. Middlewares
25.1. Usage
25.2. Configuration
25.3. Routing middleware
25.4. Handler middleware
26. Performance
26.1. One process per connection
27. Security checklist
27.1. Instructions for AI agents
27.2. Denial of Service (DoS)
27.3. Injection attacks
27.4. Path traversal
27.5. Cryptographic and TLS considerations
27.6. Spoofing
27.7. Information disclosure
27.8. Experimental features
IX. Additional information
A. Migrating from Cowboy 2.15 to 2.16
A.1. Features added
A.2. Bugs fixed
B. Migrating from Cowboy 2.14 to 2.15
B.1. Features added
B.2. Bugs fixed
C. Migrating from Cowboy 2.13 to 2.14
C.1. Features added
C.2. Experimental features added
C.3. Optimisation-related changes
C.4. Bugs fixed
D. Migrating from Cowboy 2.12 to 2.13
D.1. Features added
D.2. Experimental features added
D.3. Features deprecated
D.4. Optimisation-related changes
D.5. Bugs fixed
E. Migrating from Cowboy 2.11 to 2.12
E.1. Features added
F. Migrating from Cowboy 2.10 to 2.11
F.1. Features added
F.2. Features removed
F.3. Bugs fixed
G. Migrating from Cowboy 2.9 to 2.10
G.1. Features added
G.2. Bugs fixed
H. Migrating from Cowboy 2.8 to 2.9
H.1. Features added
H.2. Bugs fixed
I. Migrating from Cowboy 2.7 to 2.8
I.1. Features added
I.2. Experimental features added
I.3. Features modified
I.4. Bugs fixed
J. Migrating from Cowboy 2.6 to 2.7
J.1. Features added
J.2. Experimental features added
J.3. New functions
J.4. Bugs fixed
K. Migrating from Cowboy 2.5 to 2.6
K.1. Features added
K.2. Experimental features added
K.3. Bugs fixed
L. Migrating from Cowboy 2.4 to 2.5
L.1. Features added
L.2. Experimental features added
L.3. New functions
L.4. Bugs fixed
M. Migrating from Cowboy 2.3 to 2.4
M.1. Features added
M.2. Bugs fixed
N. Migrating from Cowboy 2.2 to 2.3
N.1. Features added
N.2. Bugs fixed
O. Migrating from Cowboy 2.1 to 2.2
O.1. Features added
O.2. New functions
O.3. Bugs fixed
P. Migrating from Cowboy 2.0 to 2.1
P.1. Features added
P.2. Experimental features added
P.3. Changed behaviors
P.4. New functions
P.5. Bugs fixed
Q. Migrating from Cowboy 1.0 to 2.0
Q.1. Compatibility
Q.2. Features added
Q.3. Features removed
Q.4. Changed behaviors
Q.5. New functions
Q.6. Changed functions
Q.7. Removed functions
Q.8. Other changes
R. HTTP and other specifications
R.1. HTTP
R.2. URL
R.3. WebDAV
R.4. CoAP