| 1 |
= cowboy_http2(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy_http2 - HTTP/2 |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
The module `cowboy_http2` implements HTTP/2 |
| 10 |
as a Ranch protocol. |
| 11 |
|
| 12 |
== Options |
| 13 |
|
| 14 |
// @todo Might be worth moving cowboy_clear/tls/stream_h options |
| 15 |
// to their respective manual, when they are added. |
| 16 |
|
| 17 |
[source,erlang] |
| 18 |
---- |
| 19 |
opts() :: #{ |
| 20 |
active_n => pos_integer(), |
| 21 |
alpn_default_protocol => http | http2, |
| 22 |
connection_type => worker | supervisor, |
| 23 |
connection_window_margin_size => 0..16#7fffffff, |
| 24 |
connection_window_update_threshold => 0..16#7fffffff, |
| 25 |
dynamic_buffer => false | {pos_integer(), pos_integer()}, |
| 26 |
enable_connect_protocol => boolean(), |
| 27 |
goaway_initial_timeout => timeout(), |
| 28 |
goaway_complete_timeout => timeout(), |
| 29 |
hibernate => boolean(), |
| 30 |
idle_timeout => timeout(), |
| 31 |
inactivity_timeout => timeout(), |
| 32 |
initial_connection_window_size => 65535..16#7fffffff, |
| 33 |
initial_stream_window_size => 0..16#7fffffff, |
| 34 |
linger_timeout => timeout(), |
| 35 |
logger => module(), |
| 36 |
max_authority_length => non_neg_integer(), |
| 37 |
max_cancel_stream_rate => {pos_integer(), timeout()}, |
| 38 |
max_concurrent_streams => non_neg_integer() | infinity, |
| 39 |
max_connection_buffer_size => non_neg_integer(), |
| 40 |
max_connection_window_size => 0..16#7fffffff, |
| 41 |
max_decode_table_size => non_neg_integer(), |
| 42 |
max_encode_table_size => non_neg_integer(), |
| 43 |
max_fragmented_header_block_size => 16384..16#7fffffff, |
| 44 |
max_frame_size_received => 16384..16777215, |
| 45 |
max_frame_size_sent => 16384..16777215 | infinity, |
| 46 |
max_headers => non_neg_integer(), |
| 47 |
max_received_frame_rate => {pos_integer(), timeout()}, |
| 48 |
max_reset_stream_rate => {pos_integer(), timeout()}, |
| 49 |
max_stream_buffer_size => non_neg_integer(), |
| 50 |
max_stream_window_size => 0..16#7fffffff, |
| 51 |
preface_timeout => timeout(), |
| 52 |
protocols => [http | http2], |
| 53 |
proxy_header => boolean(), |
| 54 |
reset_idle_timeout_on_send => boolean(), |
| 55 |
sendfile => boolean(), |
| 56 |
settings_timeout => timeout(), |
| 57 |
stream_handlers => [module()], |
| 58 |
stream_window_data_threshold => 0..16#7fffffff, |
| 59 |
stream_window_margin_size => 0..16#7fffffff, |
| 60 |
stream_window_update_threshold => 0..16#7fffffff |
| 61 |
} |
| 62 |
---- |
| 63 |
|
| 64 |
Configuration for the HTTP/2 protocol. |
| 65 |
|
| 66 |
This configuration is passed to Cowboy when starting listeners |
| 67 |
using `cowboy:start_clear/3` or `cowboy:start_tls/3` functions. |
| 68 |
|
| 69 |
It can be updated without restarting listeners using the |
| 70 |
Ranch functions `ranch:get_protocol_options/1` and |
| 71 |
`ranch:set_protocol_options/2`. |
| 72 |
|
| 73 |
The default value is given next to the option name: |
| 74 |
|
| 75 |
active_n (1):: |
| 76 |
|
| 77 |
The number of packets Cowboy will request from the socket at once. |
| 78 |
This can be used to tweak the performance of the server. Higher |
| 79 |
values reduce the number of times Cowboy need to request more |
| 80 |
packets from the port driver at the expense of potentially |
| 81 |
higher memory being used. |
| 82 |
|
| 83 |
alpn_default_protocol (http):: |
| 84 |
|
| 85 |
Default protocol to use when the client connects over TLS |
| 86 |
without ALPN. Can be set to `http2` to disable HTTP/1.1 |
| 87 |
entirely. |
| 88 |
|
| 89 |
connection_type (supervisor):: |
| 90 |
|
| 91 |
Whether the connection process also acts as a supervisor. |
| 92 |
|
| 93 |
connection_window_margin_size (65535):: |
| 94 |
|
| 95 |
Extra amount in bytes to be added to the window size when |
| 96 |
updating the connection window. This is used to |
| 97 |
ensure that there is always some space available in |
| 98 |
the window. |
| 99 |
|
| 100 |
connection_window_update_threshold (163840):: |
| 101 |
|
| 102 |
The connection window will only get updated when its size |
| 103 |
becomes lower than this threshold, in bytes. This is to |
| 104 |
avoid sending too many `WINDOW_UPDATE` frames. |
| 105 |
|
| 106 |
dynamic_buffer ({1024, 131072}):: |
| 107 |
|
| 108 |
Cowboy will dynamically change the socket's `buffer` size |
| 109 |
depending on the size of the data it receives from the socket. |
| 110 |
This lets Cowboy use the optimal buffer size for the current |
| 111 |
workload. |
| 112 |
+ |
| 113 |
The dynamic buffer size functionality can be disabled by |
| 114 |
setting this option to `false`. Cowboy will also disable |
| 115 |
it by default when the `buffer` transport option is configured. |
| 116 |
|
| 117 |
enable_connect_protocol (false):: |
| 118 |
|
| 119 |
Whether to enable the extended CONNECT method to allow |
| 120 |
protocols like Websocket to be used over an HTTP/2 stream. |
| 121 |
+ |
| 122 |
For backward compatibility reasons, this option is disabled |
| 123 |
by default. It must be enabled to use Websocket over HTTP/2. |
| 124 |
It will be enabled by default in a future release. |
| 125 |
|
| 126 |
goaway_initial_timeout (1000):: |
| 127 |
|
| 128 |
Time in ms to wait for any in-flight stream creations before stopping to accept |
| 129 |
new streams on an existing connection during a graceful shutdown. |
| 130 |
|
| 131 |
goaway_complete_timeout (3000):: |
| 132 |
|
| 133 |
Time in ms to wait for ongoing streams to complete before closing the connection |
| 134 |
during a graceful shutdown. |
| 135 |
|
| 136 |
hibernate (false):: |
| 137 |
|
| 138 |
Whether the connection process will hibernate automatically. |
| 139 |
|
| 140 |
idle_timeout (60000):: |
| 141 |
|
| 142 |
Time in ms with no data received before Cowboy closes the connection. |
| 143 |
|
| 144 |
inactivity_timeout (300000):: |
| 145 |
|
| 146 |
**DEPRECATED** Time in ms with nothing received at all before Cowboy closes the connection. |
| 147 |
|
| 148 |
initial_connection_window_size (65535):: |
| 149 |
|
| 150 |
Initial window size in bytes for the connection. This is the total amount |
| 151 |
of data (from request bodies for example) that may be buffered |
| 152 |
by the connection across all streams before the user code |
| 153 |
explicitly requests it. |
| 154 |
+ |
| 155 |
Note that this value cannot be lower than the default. |
| 156 |
|
| 157 |
initial_stream_window_size (65535):: |
| 158 |
|
| 159 |
Initial window size in bytes for new streams. This is the total amount |
| 160 |
of data (from request bodies for example) that may be buffered |
| 161 |
by a single stream before the user code explicitly requests it. |
| 162 |
|
| 163 |
linger_timeout (1000):: |
| 164 |
|
| 165 |
Time in ms that Cowboy will wait when closing the connection. This is |
| 166 |
necessary to avoid the TCP reset problem as described in the |
| 167 |
https://tools.ietf.org/html/rfc7230#section-6.6[section 6.6 of RFC7230]. |
| 168 |
In HTTP/2's case the GOAWAY message might also be lost when |
| 169 |
closing the connection immediately. |
| 170 |
|
| 171 |
logger (error_logger):: |
| 172 |
|
| 173 |
The module that will be used to write log messages. |
| 174 |
|
| 175 |
max_authority_length (255):: |
| 176 |
|
| 177 |
Maximum length of the authority component of the target URI. |
| 178 |
This is a hard limit. |
| 179 |
|
| 180 |
max_cancel_stream_rate ({500, 10000}):: |
| 181 |
|
| 182 |
Maximum cancel stream rate per connection. This can be used to |
| 183 |
protect against misbehaving or malicious peers, by limiting the |
| 184 |
number of streams that the peer can reset over a certain time period. |
| 185 |
The rate is expressed as a tuple `{NumCancels, TimeMs}`. This is |
| 186 |
similar to a supervisor restart intensity/period. |
| 187 |
|
| 188 |
max_concurrent_streams (100):: |
| 189 |
|
| 190 |
Maximum number of concurrent streams allowed on the connection. |
| 191 |
|
| 192 |
max_connection_buffer_size (16000000):: |
| 193 |
|
| 194 |
Maximum size of all stream buffers for this connection, in bytes. |
| 195 |
This is a soft limit used to apply backpressure to handlers that |
| 196 |
send data faster than the HTTP/2 connection allows. |
| 197 |
|
| 198 |
max_connection_window_size (16#7fffffff):: |
| 199 |
|
| 200 |
Maximum connection window size in bytes. This is used as an upper bound |
| 201 |
when calculating the window size, either when reading the request |
| 202 |
body or receiving said body. |
| 203 |
|
| 204 |
max_decode_table_size (4096):: |
| 205 |
|
| 206 |
Maximum header table size in bytes used by the decoder. This is the value |
| 207 |
advertised to the client. The client can then choose a header table size |
| 208 |
equal or lower to the advertised value. |
| 209 |
|
| 210 |
max_encode_table_size (4096):: |
| 211 |
|
| 212 |
Maximum header table size in bytes used by the encoder. The server will |
| 213 |
compare this value to what the client advertises and choose the smallest |
| 214 |
one as the encoder's header table size. |
| 215 |
|
| 216 |
max_fragmented_header_block_size (32768):: |
| 217 |
|
| 218 |
Maximum header block size when headers are split over multiple HEADERS |
| 219 |
and CONTINUATION frames. Clients that attempt to send header blocks |
| 220 |
larger than this value will receive an ENHANCE_YOUR_CALM connection |
| 221 |
error. Note that this value is not advertised and should be large |
| 222 |
enough for legitimate requests. |
| 223 |
|
| 224 |
max_frame_size_received (16384):: |
| 225 |
|
| 226 |
Maximum size in bytes of the frames received by the server. This value is |
| 227 |
advertised to the remote endpoint which can then decide to use |
| 228 |
any value lower or equal for its frame sizes. |
| 229 |
+ |
| 230 |
It is highly recommended to increase this value for performance reasons. |
| 231 |
In a future Cowboy version the default will be increased to 1MB (1048576). |
| 232 |
Too low values may result in very large file uploads failing because |
| 233 |
Cowboy will detect the large number of frames as flood and close the |
| 234 |
connection. |
| 235 |
|
| 236 |
max_frame_size_sent (infinity):: |
| 237 |
|
| 238 |
Maximum size in bytes of the frames sent by the server. This option allows |
| 239 |
setting an upper limit to the frame sizes instead of blindly |
| 240 |
following the client's advertised maximum. |
| 241 |
+ |
| 242 |
Note that actual frame sizes may be lower than the limit when |
| 243 |
there is not enough space left in the flow control window. |
| 244 |
|
| 245 |
max_headers (100):: |
| 246 |
|
| 247 |
Maximum number of header fields allowed per request field blocks. |
| 248 |
This option is applied independently to header and trailer |
| 249 |
field blocks. |
| 250 |
|
| 251 |
max_received_frame_rate ({10000, 10000}):: |
| 252 |
|
| 253 |
Maximum frame rate allowed per connection. The rate is expressed |
| 254 |
as a tuple `{NumFrames, TimeMs}` indicating how many frames are |
| 255 |
allowed over the given time period. This is similar to a supervisor |
| 256 |
restart intensity/period. |
| 257 |
|
| 258 |
max_reset_stream_rate ({10, 10000}):: |
| 259 |
|
| 260 |
Maximum reset stream rate per connection. This can be used to |
| 261 |
protect against misbehaving or malicious peers that do not follow |
| 262 |
the protocol, leading to the server resetting streams, by limiting |
| 263 |
the number of streams that can be reset over a certain time period. |
| 264 |
The rate is expressed as a tuple `{NumResets, TimeMs}`. This is |
| 265 |
similar to a supervisor restart intensity/period. |
| 266 |
|
| 267 |
max_stream_buffer_size (8000000):: |
| 268 |
|
| 269 |
Maximum stream buffer size in bytes. This is a soft limit used |
| 270 |
to apply backpressure to handlers that send data faster than |
| 271 |
the HTTP/2 connection allows. |
| 272 |
|
| 273 |
max_stream_window_size (16#7fffffff):: |
| 274 |
|
| 275 |
Maximum stream window size in bytes. This is used as an upper bound |
| 276 |
when calculating the window size, either when reading the request |
| 277 |
body or receiving said body. |
| 278 |
|
| 279 |
preface_timeout (5000):: |
| 280 |
|
| 281 |
Time in ms Cowboy is willing to wait for the connection preface. |
| 282 |
|
| 283 |
protocols ([http2, http]):: |
| 284 |
|
| 285 |
Protocols that may be used when the client connects over |
| 286 |
cleartext TCP. The default is to allow both HTTP/1.1 and |
| 287 |
HTTP/2. HTTP/1.1 and HTTP/2 can be disabled entirely by |
| 288 |
omitting them from the list. |
| 289 |
|
| 290 |
proxy_header (false):: |
| 291 |
|
| 292 |
Whether incoming connections have a PROXY protocol header. The |
| 293 |
proxy information will be passed forward via the `proxy_header` |
| 294 |
key of the Req object. |
| 295 |
|
| 296 |
reset_idle_timeout_on_send (false):: |
| 297 |
|
| 298 |
Whether the `idle_timeout` gets reset when sending data |
| 299 |
to the socket. |
| 300 |
|
| 301 |
sendfile (true):: |
| 302 |
|
| 303 |
Whether the sendfile syscall may be used. It can be useful to disable |
| 304 |
it on systems where the syscall has a buggy implementation, for example |
| 305 |
under VirtualBox when using shared folders. |
| 306 |
|
| 307 |
settings_timeout (5000):: |
| 308 |
|
| 309 |
Time in ms Cowboy is willing to wait for a SETTINGS ack. |
| 310 |
|
| 311 |
stream_handlers ([cowboy_stream_h]):: |
| 312 |
|
| 313 |
Ordered list of stream handlers that will handle all stream events. |
| 314 |
|
| 315 |
stream_window_data_threshold (16384):: |
| 316 |
|
| 317 |
Window threshold in bytes below which Cowboy will not attempt |
| 318 |
to send data, with one exception. When Cowboy has data to send |
| 319 |
and the window is high enough, Cowboy will always send the data, |
| 320 |
regardless of this option. |
| 321 |
|
| 322 |
stream_window_margin_size (65535):: |
| 323 |
|
| 324 |
Extra amount in bytes to be added to the window size when |
| 325 |
updating a stream's window. This is used to |
| 326 |
ensure that there is always some space available in |
| 327 |
the window. |
| 328 |
|
| 329 |
stream_window_update_threshold (163840):: |
| 330 |
|
| 331 |
A stream's window will only get updated when its size |
| 332 |
becomes lower than this threshold, in bytes. This is to avoid sending |
| 333 |
too many `WINDOW_UPDATE` frames. |
| 334 |
|
| 335 |
== Changelog |
| 336 |
|
| 337 |
* *2.17*: The `max_concurrent_streams` option now defaults to 100. |
| 338 |
* *2.17*: The `max_authority_length` option was added. |
| 339 |
* *2.16*: The `max_headers` option was added. |
| 340 |
* *2.13*: The `inactivity_timeout` option was deprecated. |
| 341 |
* *2.13*: The `active_n` default value was changed to `1`. |
| 342 |
* *2.13*: The `dynamic_buffer` and `hibernate` options were added. |
| 343 |
* *2.11*: Websocket over HTTP/2 is now considered stable. |
| 344 |
* *2.11*: The `reset_idle_timeout_on_send` option was added. |
| 345 |
* *2.11*: Add the option `max_cancel_stream_rate` to protect |
| 346 |
against another flood scenario. |
| 347 |
* *2.9*: The `goaway_initial_timeout` and `goaway_complete_timeout` |
| 348 |
options were added. |
| 349 |
* *2.8*: The `active_n` option was added. |
| 350 |
* *2.8*: The `linger_timeout` option was added. |
| 351 |
* *2.8*: The `max_received_frame_rate` default value has |
| 352 |
been multiplied by 10 as the default was too low. |
| 353 |
* *2.7*: Add the options `connection_window_margin_size`, |
| 354 |
`connection_window_update_threshold`, |
| 355 |
`max_connection_window_size`, `max_stream_window_size`, |
| 356 |
`stream_window_margin_size` and |
| 357 |
`stream_window_update_threshold` to configure |
| 358 |
behavior on sending WINDOW_UPDATE frames; |
| 359 |
`max_connection_buffer_size` and |
| 360 |
`max_stream_buffer_size` to apply backpressure |
| 361 |
when sending data too fast; |
| 362 |
`max_received_frame_rate` and `max_reset_stream_rate` |
| 363 |
to protect against various flood scenarios; and |
| 364 |
`stream_window_data_threshold` to control how small |
| 365 |
the DATA frames that Cowboy sends can get. |
| 366 |
* *2.7*: The `logger` option was added. |
| 367 |
* *2.6*: The `proxy_header` and `sendfile` options were added. |
| 368 |
* *2.4*: Add the options `initial_connection_window_size`, |
| 369 |
`initial_stream_window_size`, `max_concurrent_streams`, |
| 370 |
`max_decode_table_size`, `max_encode_table_size`, |
| 371 |
`max_frame_size_received`, `max_frame_size_sent` |
| 372 |
and `settings_timeout` to configure HTTP/2 SETTINGS |
| 373 |
and related behavior. |
| 374 |
* *2.4*: Add the option `enable_connect_protocol`. |
| 375 |
* *2.0*: Protocol introduced. |
| 376 |
|
| 377 |
== See also |
| 378 |
|
| 379 |
link:man:cowboy(7)[cowboy(7)], |
| 380 |
link:man:cowboy_http(3)[cowboy_http(3)], |
| 381 |
link:man:cowboy_websocket(3)[cowboy_websocket(3)] |