cowboy_http2.asciidoc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. = cowboy_http2(3)
  2. == Name
  3. cowboy_http2 - HTTP/2
  4. == Description
  5. The module `cowboy_http2` implements HTTP/2
  6. as a Ranch protocol.
  7. == Options
  8. // @todo Might be worth moving cowboy_clear/tls/stream_h options
  9. // to their respective manual, when they are added.
  10. [source,erlang]
  11. ----
  12. opts() :: #{
  13. active_n => pos_integer(),
  14. connection_type => worker | supervisor,
  15. connection_window_margin_size => 0..16#7fffffff,
  16. connection_window_update_threshold => 0..16#7fffffff,
  17. enable_connect_protocol => boolean(),
  18. idle_timeout => timeout(),
  19. inactivity_timeout => timeout(),
  20. initial_connection_window_size => 65535..16#7fffffff,
  21. initial_stream_window_size => 0..16#7fffffff,
  22. logger => module(),
  23. max_concurrent_streams => non_neg_integer() | infinity,
  24. max_connection_buffer_size => non_neg_integer(),
  25. max_connection_window_size => 0..16#7fffffff,
  26. max_decode_table_size => non_neg_integer(),
  27. max_encode_table_size => non_neg_integer(),
  28. max_frame_size_received => 16384..16777215,
  29. max_frame_size_sent => 16384..16777215 | infinity,
  30. max_received_frame_rate => {pos_integer(), timeout()},
  31. max_reset_stream_rate => {pos_integer(), timeout()},
  32. max_stream_buffer_size => non_neg_integer(),
  33. max_stream_window_size => 0..16#7fffffff,
  34. preface_timeout => timeout(),
  35. proxy_header => boolean(),
  36. sendfile => boolean(),
  37. settings_timeout => timeout(),
  38. stream_handlers => [module()],
  39. stream_window_data_threshold => 0..16#7fffffff,
  40. stream_window_margin_size => 0..16#7fffffff,
  41. stream_window_update_threshold => 0..16#7fffffff
  42. }
  43. ----
  44. Configuration for the HTTP/2 protocol.
  45. This configuration is passed to Cowboy when starting listeners
  46. using `cowboy:start_clear/3` or `cowboy:start_tls/3` functions.
  47. It can be updated without restarting listeners using the
  48. Ranch functions `ranch:get_protocol_options/1` and
  49. `ranch:set_protocol_options/2`.
  50. The default value is given next to the option name:
  51. active_n (100)::
  52. The number of packets Cowboy will request from the socket at once.
  53. This can be used to tweak the performance of the server. Higher
  54. values reduce the number of times Cowboy need to request more
  55. packets from the port driver at the expense of potentially
  56. higher memory being used.
  57. connection_type (supervisor)::
  58. Whether the connection process also acts as a supervisor.
  59. connection_window_margin_size (65535)::
  60. Extra amount in bytes to be added to the window size when
  61. updating the connection window. This is used to
  62. ensure that there is always some space available in
  63. the window.
  64. connection_window_update_threshold (163840)::
  65. The connection window will only get updated when its size
  66. becomes lower than this threshold, in bytes. This is to
  67. avoid sending too many `WINDOW_UPDATE` frames.
  68. enable_connect_protocol (false)::
  69. Whether to enable the extended CONNECT method to allow
  70. protocols like Websocket to be used over an HTTP/2 stream.
  71. This option is experimental and disabled by default.
  72. idle_timeout (60000)::
  73. Time in ms with no data received before Cowboy closes the connection.
  74. inactivity_timeout (300000)::
  75. Time in ms with nothing received at all before Cowboy closes the connection.
  76. initial_connection_window_size (65535)::
  77. Initial window size in bytes for the connection. This is the total amount
  78. of data (from request bodies for example) that may be buffered
  79. by the connection across all streams before the user code
  80. explicitly requests it.
  81. +
  82. Note that this value cannot be lower than the default.
  83. initial_stream_window_size (65535)::
  84. Initial window size in bytes for new streams. This is the total amount
  85. of data (from request bodies for example) that may be buffered
  86. by a single stream before the user code explicitly requests it.
  87. logger (error_logger)::
  88. The module that will be used to write log messages.
  89. max_concurrent_streams (infinity)::
  90. Maximum number of concurrent streams allowed on the connection.
  91. max_connection_buffer_size (16000000)::
  92. Maximum size of all stream buffers for this connection, in bytes.
  93. This is a soft limit used to apply backpressure to handlers that
  94. send data faster than the HTTP/2 connection allows.
  95. max_connection_window_size (16#7fffffff)::
  96. Maximum connection window size in bytes. This is used as an upper bound
  97. when calculating the window size, either when reading the request
  98. body or receiving said body.
  99. max_decode_table_size (4096)::
  100. Maximum header table size in bytes used by the decoder. This is the value
  101. advertised to the client. The client can then choose a header table size
  102. equal or lower to the advertised value.
  103. max_encode_table_size (4096)::
  104. Maximum header table size in bytes used by the encoder. The server will
  105. compare this value to what the client advertises and choose the smallest
  106. one as the encoder's header table size.
  107. max_frame_size_received (16384)::
  108. Maximum size in bytes of the frames received by the server. This value is
  109. advertised to the remote endpoint which can then decide to use
  110. any value lower or equal for its frame sizes.
  111. max_frame_size_sent (infinity)::
  112. Maximum size in bytes of the frames sent by the server. This option allows
  113. setting an upper limit to the frame sizes instead of blindly
  114. following the client's advertised maximum.
  115. +
  116. Note that actual frame sizes may be lower than the limit when
  117. there is not enough space left in the flow control window.
  118. max_received_frame_rate ({10000, 10000})::
  119. Maximum frame rate allowed per connection. The rate is expressed
  120. as a tuple `{NumFrames, TimeMs}` indicating how many frames are
  121. allowed over the given time period. This is similar to a supervisor
  122. restart intensity/period.
  123. max_reset_stream_rate ({10, 10000})::
  124. Maximum reset stream rate per connection. This can be used to
  125. protect against misbehaving or malicious peers that do not follow
  126. the protocol, leading to the server resetting streams, by limiting
  127. the number of streams that can be reset over a certain time period.
  128. The rate is expressed as a tuple `{NumResets, TimeMs}`. This is
  129. similar to a supervisor restart intensity/period.
  130. max_stream_buffer_size (8000000)::
  131. Maximum stream buffer size in bytes. This is a soft limit used
  132. to apply backpressure to handlers that send data faster than
  133. the HTTP/2 connection allows.
  134. max_stream_window_size (16#7fffffff)::
  135. Maximum stream window size in bytes. This is used as an upper bound
  136. when calculating the window size, either when reading the request
  137. body or receiving said body.
  138. preface_timeout (5000)::
  139. Time in ms Cowboy is willing to wait for the connection preface.
  140. proxy_header (false)::
  141. Whether incoming connections have a PROXY protocol header. The
  142. proxy information will be passed forward via the `proxy_header`
  143. key of the Req object.
  144. sendfile (true)::
  145. Whether the sendfile syscall may be used. It can be useful to disable
  146. it on systems where the syscall has a buggy implementation, for example
  147. under VirtualBox when using shared folders.
  148. settings_timeout (5000)::
  149. Time in ms Cowboy is willing to wait for a SETTINGS ack.
  150. stream_handlers ([cowboy_stream_h])::
  151. Ordered list of stream handlers that will handle all stream events.
  152. stream_window_data_threshold (16384)::
  153. Window threshold in bytes below which Cowboy will not attempt
  154. to send data, with one exception. When Cowboy has data to send
  155. and the window is high enough, Cowboy will always send the data,
  156. regardless of this option.
  157. stream_window_margin_size (65535)::
  158. Extra amount in bytes to be added to the window size when
  159. updating a stream's window. This is used to
  160. ensure that there is always some space available in
  161. the window.
  162. stream_window_update_threshold (163840)::
  163. A stream's window will only get updated when its size
  164. becomes lower than this threshold, in bytes. This is to avoid sending
  165. too many `WINDOW_UPDATE` frames.
  166. == Changelog
  167. * *2.8*: The `active_n` option was added.
  168. * *2.8*: The `max_received_frame_rate` default value has
  169. been multiplied by 10 as the default was too low.
  170. * *2.7*: Add the options `connection_window_margin_size`,
  171. `connection_window_update_threshold`,
  172. `max_connection_window_size`, `max_stream_window_size`,
  173. `stream_window_margin_size` and
  174. `stream_window_update_threshold` to configure
  175. behavior on sending WINDOW_UPDATE frames;
  176. `max_connection_buffer_size` and
  177. `max_stream_buffer_size` to apply backpressure
  178. when sending data too fast;
  179. `max_received_frame_rate` and `max_reset_stream_rate`
  180. to protect against various flood scenarios; and
  181. `stream_window_data_threshold` to control how small
  182. the DATA frames that Cowboy sends can get.
  183. * *2.7*: The `logger` option was added.
  184. * *2.6*: The `proxy_header` and `sendfile` options were added.
  185. * *2.4*: Add the options `initial_connection_window_size`,
  186. `initial_stream_window_size`, `max_concurrent_streams`,
  187. `max_decode_table_size`, `max_encode_table_size`,
  188. `max_frame_size_received`, `max_frame_size_sent`
  189. and `settings_timeout` to configure HTTP/2 SETTINGS
  190. and related behavior.
  191. * *2.4*: Add the experimental option `enable_connect_protocol`.
  192. * *2.0*: Protocol introduced.
  193. == See also
  194. link:man:cowboy(7)[cowboy(7)],
  195. link:man:cowboy_http(3)[cowboy_http(3)],
  196. link:man:cowboy_websocket(3)[cowboy_websocket(3)]