| 1 |
[appendix] |
| 2 |
== Migrating from Cowboy 2.0 to 2.1 |
| 3 |
|
| 4 |
Cowboy 2.1 focused on adding features that were temporarily |
| 5 |
removed in Cowboy 2.0. A number of bugs found in the 2.0 |
| 6 |
release were also fixed. |
| 7 |
|
| 8 |
=== Features added |
| 9 |
|
| 10 |
* It is now possible to obtain the client TLS certificate |
| 11 |
and the local IP/port for the connection from the Req object. |
| 12 |
|
| 13 |
* Informational responses (1XX responses) can now be sent. |
| 14 |
They must be sent before initiating the final response. |
| 15 |
|
| 16 |
* The `expect: 100-continue` header is now handled |
| 17 |
automatically. The 100 response will be sent on the |
| 18 |
first `cowboy_req:read_body/2,3,4` call. This only applies |
| 19 |
when using the default `cowboy_stream_h` stream handler. |
| 20 |
|
| 21 |
=== Experimental features added |
| 22 |
|
| 23 |
Experimental features are previews of features that will be |
| 24 |
added in a future release. They are not documented and their |
| 25 |
interface may change at any time. You are welcome to try them |
| 26 |
and provide feedback. |
| 27 |
|
| 28 |
* The `cowboy_metrics_h` stream handler can be used to |
| 29 |
extract metrics out of Cowboy. It must be used first in |
| 30 |
the list of stream handlers, and will record all events |
| 31 |
related to requests, responses and spawned processes. |
| 32 |
When the stream terminates it will pass this information |
| 33 |
to a user-defined callback. |
| 34 |
|
| 35 |
* The `cowboy_tracer_h` stream handler can be used to setup |
| 36 |
automatic tracing of specific requests. You can conditionally |
| 37 |
enable tracing based on a function, header, path or any other |
| 38 |
element from the request and the trace will apply to the |
| 39 |
entire connection and any processes created by it. This is |
| 40 |
meant to be used for debugging both in tests and production. |
| 41 |
|
| 42 |
=== Changed behaviors |
| 43 |
|
| 44 |
* The `cowboy_rest` handler now implements a mechanism for |
| 45 |
switching to a different type of handler from any callback |
| 46 |
where `stop` is also allowed. Switch by returning |
| 47 |
`{switch_handler, Module}` or `{switch_handler, Module, Opts}`. |
| 48 |
This is especially useful for switching to `cowboy_loop` |
| 49 |
for streaming the request or response body. |
| 50 |
|
| 51 |
* REST callbacks that do not allow `stop` as a return value |
| 52 |
are now explicitly listed in the documentation. |
| 53 |
|
| 54 |
=== New functions |
| 55 |
|
| 56 |
* The function `cowboy_req:sock/1` returns the IP/port |
| 57 |
of the local socket. |
| 58 |
|
| 59 |
* The function `cowboy_req:cert/1` returns the client |
| 60 |
TLS certificate or `undefined` if it isn't available. |
| 61 |
|
| 62 |
* The function `cowboy_req:inform/2,3` sends an |
| 63 |
informational response. |
| 64 |
|
| 65 |
=== Bugs fixed |
| 66 |
|
| 67 |
* Ensure HTTP/2 connections are not closed prematurely |
| 68 |
when the user code does not read the request body. |
| 69 |
|
| 70 |
* Ensure HTTP/1.1 streams are not terminated too early. |
| 71 |
Their behavior is now consistent with the HTTP/2 code |
| 72 |
where the stream handler is only terminated when the |
| 73 |
`stop` command is returned. |
| 74 |
|
| 75 |
* Sending zero-sized data from stream handlers or from |
| 76 |
`cowboy_req:stream_body/3` could lead to issues with |
| 77 |
HTTP/1.1. This has been fixed. |
| 78 |
|
| 79 |
* The final chunk sent by Cowboy when it terminates a |
| 80 |
chunked body after the handler process exits was not |
| 81 |
passed through stream handlers, which could lead to |
| 82 |
issues when `cowboy_compress_h` was being used. This |
| 83 |
is now corrected. |
| 84 |
|
| 85 |
* The stream handler state was discarded in some cases |
| 86 |
where Cowboy had to send a response or response data |
| 87 |
automatically when ending a stream. This has now |
| 88 |
been corrected. |
| 89 |
|
| 90 |
* The stream handler callback `terminate/3` will now be |
| 91 |
called when switching to another protocol using the |
| 92 |
command `switch_protocol`. This doesn't apply when |
| 93 |
doing upgrades to HTTP/2 as those occur before the |
| 94 |
stream is initialized. |
| 95 |
|
| 96 |
* Cowlib has been updated to 2.0.1 to fix an issue with |
| 97 |
Websocket compression when using Erlang/OTP 20.1. Note |
| 98 |
that at the time of writing all 20.1 versions (from |
| 99 |
20.1 to 20.1.4) have issues when compression is enabled. |
| 100 |
It is expected to work properly from 20.1.5 onward. In |
| 101 |
the meantime it is recommended to run the plain 20.1 |
| 102 |
release and disable Websocket compression, or use a |
| 103 |
release before 20.1. |
| 104 |
|
| 105 |
* Cowboy will no longer crash when the `cowboy_clock` |
| 106 |
process is not running. This can happen when Cowboy |
| 107 |
is being restarted during upgrades, for example. |