migrating_from_2.6.asciidoc 8.0 KB

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