Debian Codegraph @

doc/src/guide/migrating_from_2.6.asciidoc

raw
1 [appendix]
2 == Migrating from Cowboy 2.6 to 2.7
3
4 Cowboy 2.7 improves the HTTP/2 code with optimizations
5 around the sending of DATA and WINDOW_UPDATE frames;
6 graceful shutdown of the connection when the client is
7 going away; and rate limiting mechanisms. New options
8 and mechanisms have also been added to control the
9 amount of memory Cowboy ends up using with both HTTP/1.1
10 and HTTP/2. Much, but not all, of this work was done
11 to address HTTP/2 CVEs about potential denial of service.
12
13 In addition, many of the experimental features introduced
14 in previous releases have been marked stable and are now
15 documented.
16
17 Cowboy 2.7 requires Erlang/OTP 20.0 or greater.
18
19 === Features added
20
21 * Cowboy is now compatible with both Ranch 1.7 and the
22 upcoming Ranch 2.0.
23
24 * The number of HTTP/2 WINDOW_UPDATE frames Cowboy sends
25 has been greatly reduced. Cowboy now applies heuristics
26 to determine whether it is necessary to update the window,
27 based on the current window size and the amount of data
28 requested by streams (the `cowboy_req:read_body/2` length
29 for example). Six new options have been added to control
30 this behavior: `connection_window_margin_size`,
31 `connection_window_update_threshold`,
32 `max_connection_window_size`, `max_stream_window_size`,
33 `stream_window_margin_size` and
34 `stream_window_update_threshold`.
35
36 * HTTP/2 connections will now be shut down gracefully
37 when receiving a GOAWAY frame. Cowboy will simply
38 wait for existing streams to finish before closing
39 the connection.
40
41 * Functions that stream the response body now have
42 backpressure applied. They now wait for a message
43 to be sent back. The message will be held off when
44 using HTTP/2 and the buffer sizes exceed either
45 `max_connection_buffer_size` or `max_stream_buffer_size`.
46 For HTTP/1.1 the data is sent synchronously and we
47 rely instead on the TCP backpressure.
48
49 * A new HTTP/2 option `stream_window_data_threshold`
50 can be used to control how little the DATA frames that
51 Cowboy sends can get. By default Cowboy will wait for
52 the window to be large enough to send either everything
53 queued or to reach the default maximum frame size of
54 16384 bytes.
55
56 * A new HTTP/2 option `max_receive_frame_rate` can be
57 used to control how fast the server is willing to receive
58 frames. By default it will accept 1000 frames every 10
59 seconds.
60
61 * A new HTTP/2 option `max_reset_stream_rate` can be
62 used to control the rate of errors the server is
63 willing to accept. By default it will accept 10
64 stream resets every 10 seconds.
65
66 * Flow control for incoming data has been implemented
67 for HTTP/1.1. Cowboy will now wait for the user code
68 to ask for the request body before reading it from
69 the socket. The option `initial_stream_flow_size`
70 controls how much data Cowboy will read without
71 being asked.
72
73 * The HTTP/1.1 and HTTP/2 option `logger` is now
74 documented.
75
76 * The Websocket option `validate_utf8` has been
77 added. It can be used to disable the expensive UTF-8
78 validation for incoming text and close frames.
79
80 * The experimental commands based Websocket interface
81 is now considered stable and has been documented.
82 The old interface is now deprecated.
83
84 * A new Websocket handler command `shutdown_reason`
85 can be used to change the normal exit reason of
86 Websocket processes. By default `normal` is used;
87 with this command the exit reason can be changed
88 to `{shutdown, ShutdownReason}`.
89
90 * The experimental stream handlers `cowboy_metrics_h`
91 and `cowboy_tracer_h` are now considered stable and
92 have been documented.
93
94 * The stream handler commands `set_options` and `log`
95 are now considered stable and have been documented.
96
97 * The router is now capable of retrieving dispatch
98 rules directly from the `persistent_term` storage
99 (available starting from Erlang/OTP 21.2).
100
101 * Support for the status codes 208 and 508 has been
102 added.
103
104 * Update Ranch to 1.7.1.
105
106 * Update Cowlib to 2.8.0.
107
108 === Experimental features added
109
110 * It is now possible to read the response body from any
111 process, as well as doing any other `cowboy_req`
112 operations. Since this is not recommended due to
113 race condition concerns this feature will always
114 remain experimental.
115
116 === New functions
117
118 * The function `cowboy_req:filter_cookies/2` has been
119 added. It can be called before parsing/matching
120 cookies in order to filter out undesirables. The
121 main reason for doing this is to avoid most parse
122 errors that may occur when dealing with Web browsers
123 (which have a string-based Javascript interface to
124 cookies that is very permissive of invalid content)
125 and to be able to recover in other cases.
126
127 * The function `cowboy_req:cast/2` has been added.
128 It can be used to send events to stream handlers.
129
130 === Bugs fixed
131
132 * A number of fixes and additions were made to address the
133 HTTP/2 CVEs CVE-2019-9511 through CVE-2019-9518, except
134 for CVE-2019-9513 which required no intervention as the
135 relevant protocol feature is not implemented by Cowboy.
136
137 * The HTTP/2 connection window could become larger than the
138 protocol allows, leading to errors. This has been corrected.
139
140 * The presence of empty header names in HTTP/2 requests now
141 results in the request to be rejected.
142
143 * Cowboy will now remove headers specific to HTTP/1.1
144 (the hop by hop headers such as connection or upgrade)
145 when building an HTTP/2 response.
146
147 * A bug in the HTTP/2 code that resulted in the failure to
148 fully send iolist response bodies has been fixed. Cowboy
149 would just wait indefinitely in those cases.
150
151 * It was possible for a final empty HTTP/2 DATA frame to get
152 stuck and never sent when the window reached 0 and the remote
153 end did not increase the window anymore. This has been
154 corrected.
155
156 * Cowboy now uses the host header when the HTTP/2
157 :authority pseudo header is missing. A common scenario
158 where this occurs is when proxies translate incoming
159 HTTP/1.1 requests to HTTP/2.
160
161 * HTTP/1.1 connections are now properly closed when the
162 user code sends less data than advertised in the response
163 headers.
164
165 * Cowboy will now close HTTP/1.1 connections immediately when
166 a header line is missing a colon separator. Previously it
167 was waiting for more data.
168
169 * It was possible for Cowboy to receive stray timeout messages
170 for HTTP/1.1 connections, resulting in crashes. The timeout
171 handling in HTTP/1.1 has been reworked and the issue should
172 no longer occur.
173
174 * The type for the Req object has been updated to accept
175 custom fields as was already documented.
176
177 * The authentication scheme returned when parsing the
178 authorization header is now case insensitive, which
179 means it will be returned as lowercase.
180
181 * Cowboy no longer discards data that follows a Websocket
182 upgrade request. Note that the protocol does not allow
183 sending data before receiving a successful Websocket
184 upgrade response, so this fix is more out of principle
185 rather than to fix a real world issue.
186
187 * The `cowboy_static` handler will now properly detect
188 the type of files that have an uppercase or mixed
189 extension component.
190
191 * The `cowboy_static` handler is now consistent across all
192 supported platforms. It now explicitly rejects `path_info`
193 components that include a forward slash, backward slash
194 or NUL character.
195
196 * The update to Ranch 1.7.1 fixes an issue with the PROXY
197 protocol that would cause checksum verification to fail.
198
199 * The HTTP/1.1 error reason for `stream_error` mistakenly
200 contained an extra element. It has now been removed.
201
202 * The `PartialReq` given to the `early_error` stream handler
203 callback now includes headers when the protocol is HTTP/2.
204
205 * A bug where the stacktrace was incorrect in error messages
206 has been fixed. The problem occurred when an exception
207 occurred in the handler's terminate callback.
208
209 * The REST flowchart for POST, PATCH and PUT has received
210 a number of fixes and had to be greatly reworked as a
211 result. When the method is PUT, we do not check for
212 the location header in the response. When the resource
213 doesn't exist and the method was PUT the flowchart was
214 largely incorrect. A 415 response may occur after the
215 `content_types_accepted` callback and was missing from
216 the flowchart.
217
218 * The documentation for `content_types_accepted` now
219 includes the media type wildcard that was previously
220 missing.
221
222 * The documentation for a type found in `cow_cookie`
223 was missing. A manual page for `cow_cookie` was added
224 and can be found in the Cowlib documentation.