Debian Codegraph @

doc/src/specs/rfc7230_server.ezdoc

raw
1 ::: RFC7230 HTTP/1.1 server
2
3 This document lists the rules the Cowboy server follows based
4 on the RFC7230 HTTP specifications.
5
6 :: Listener
7
8 The default port for "http" connections is 80. The connection
9 uses plain TCP. (RFC7230 2.7.1)
10
11 The default port for "https" connections is 443. The connection
12 uses TLS. (RFC7230 2.7.2)
13
14 Any other port may be used for either of them.
15
16 :: Before the request
17
18 A configurable number of empty lines (CRLF) preceding the request
19 must be ignored. At least 1 empty line must be ignored. (RFC7230 3.5)
20
21 When receiving a response instead of a request, identified by the
22 status-line which starts with the HTTP version, the server must
23 reject the message with a 501 status code and close the connection. (RFC7230 3.1)
24
25 :: Request
26
27 It is only necessary to parse elements required to process the
28 request. (RFC7230 2.5)
29
30 Parsed elements are subject to configurable limits. A server must
31 be able to parse elements at least as long as it generates. (RFC7230 2.5)
32
33 The request must be parsed as a sequence of octets in an encoding
34 that is a superset of US-ASCII. (RFC7230 2.5)
35
36 ```
37 HTTP-request = request-line *( header-field CRLF ) CRLF [ message-body ]
38 ```
39
40 The general format of HTTP requests is strict. No empty line is
41 allowed in-between components except for the empty line
42 indicating the end of the list of headers.
43
44 It is not necessary to read the message-body before processing
45 the request as the message-body may be dropped depending on the
46 outcome of the processing.
47
48 The time the request (request line and headers) takes to be
49 received by the server must be limited and subject to configuration.
50 A server must wait at least 5 seconds before dropping the connection.
51 A 408 status code must be sent if the request line was received
52 fully when the timeout is triggered.
53
54 An HTTP/1.1 server must understand any valid HTTP/1.0 request,
55 and respond to those with an HTTP/1.1 message that only use
56 features understood or safely ignored by HTTP/1.0 clients. (RFC7230 A)
57
58 :: Request line
59
60 It is recommended to limit the request-line length to a configurable
61 limit of at least 8000 octets. However, as the possible line length is
62 highly dependent on what form the request-target takes, it is preferrable
63 to limit each individual components of the request-target. (RFC7230 3.1.1)
64
65 A request line too long must be rejected with a 414 status code
66 and the closing of the connection. (RFC7230 3.1.1)
67
68 ```
69 method SP request-target SP version CRLF
70 ```
71
72 :: Method
73
74 ```
75 method = token ; case sensitive
76 token = 1*tchar
77 tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
78 ```
79
80 The request method is defined as 1+ token characters. An invalid
81 or empty method must be rejected with a 400 status code and the
82 closing of the connection. (RFC7230 3.1.1, RFC7230 3.2.6)
83
84 In practice the only characters in use by registered methods are
85 uppercase letters [A-Z] and the dash "-". (IANA HTTP Method Registry)
86
87 The length of the method must be subject to a configurable limit.
88 A method too long must be rejected with a 501 status code and the
89 closing of the connection. (RFC7230 3.1.1)
90
91 A good default for the method length limit is the longest method
92 length the server implements. (RFC7230 3.1.1)
93
94 :: Between method and request-target
95
96 A request that uses anything other than SP as separator between
97 the method and the request-target must be rejected with a 400
98 status code and the closing of the connection. (RFC7230 3.1.1, RFC7230 3.5)
99
100 :: Request target
101
102 There are four request-target forms. A server must be able to
103 handle at least origin-form and absolute-form. The other two
104 forms are specific to the CONNECT and site-wide OPTIONS method,
105 respectively. (RFC7230 5.3.2)
106
107 The fragment part of the target URI is not sent. It must be
108 ignored by a server receiving it. (RFC7230 5.1)
109
110 ```
111 request-target = origin-form / absolute-form / authority-form / asterisk-form
112 ```
113
114 Any other form is invalid and must be rejected with a 400
115 status code and the closing of the connection.
116
117 : origin-form
118
119 origin-form is used when the client does not connect to a proxy,
120 does not use the CONNECT method and does not issue a site-wide
121 OPTIONS request. (RFC7230 5.3.1)
122
123 ```
124 origin-form = absolute-path [ "?" query ]
125 absolute-path = 1*( "/" segment )
126 segment = *pchar
127 query = *( pchar / "/" / "?" )
128
129 pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
130 unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
131 pct-encoded = "%" HEXDIG HEXDIG
132 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
133 ```
134
135 The scheme is either resolved from configuration or is "https"
136 when on a TLS connection and "http" otherwise. (RFC7230 5.5)
137
138 The authority is sent in the host header. (RFC7230 5.3.1, RFC7230 5.5)
139
140 The absolute-path always starts with "/" and ends with either "?", "#"
141 or the end of the URI. (RFC3986 3.3)
142
143 The query starts with "?" and ends with "#" or the end of the URI. (RFC3986 3.4)
144
145 The path and query must be subject to a configurable limit.
146 This limit must be at least as high as what the server generates.
147 A good default would be 8000 characters. (RFC7230 2.5, RFC7230 3.1.1)
148
149 A request with a too long origin-form must be rejected with
150 a 414 status code and the closing of the connection. (RFC7230 3.1.1)
151
152 : absolute-form
153
154 absolute-form is used when the client connects to a proxy, though
155 its usage is also allowed when connecting to the server directly. (RFC7230 5.3.2)
156
157 In practice the scheme will be "http" or "https".
158
159 The "http" and "https" schemes based URI take the following form. (RFC7230 2.7.1, RFC7230 2.7.2)
160
161 ```
162 http-URI = "http:" "//" authority path-abempty [ "?" query ] [ "#" fragment ]
163 https-URI = "https:" "//" authority path-abempty [ "?" query ] [ "#" fragment ]
164 ```
165
166 The target URI excludes the fragment component. (RFC7230 5.1)
167
168 This means that the absolute-form uses a subset of absolute-URI.
169
170 ```
171 absolute-form = ( "http" / "https" ) "://" authority path-abempty [ "?" query ]
172 authority = host [ ":" port ]
173 path-abempty = *( "/" segment )
174 query = *( pchar / "/" / "?" )
175
176 host = IP-literal / IPv4address / reg-name
177 port = *DIGIT
178
179 IP-literal = "[" ( IPv6address / IPvFuture ) "]"
180
181 IPv6address = 6( h16 ":" ) ls32
182 / "::" 5( h16 ":" ) ls32
183 / [ h16 ] "::" 4( h16 ":" ) ls32
184 / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
185 / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
186 / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
187 / [ *4( h16 ":" ) h16 ] "::" ls32
188 / [ *5( h16 ":" ) h16 ] "::" h16
189 / [ *6( h16 ":" ) h16 ] "::"
190
191 ls32 = ( h16 ":" h16 ) / IPv4address ; least-significant 32 bits of address
192 h16 = 1*4HEXDIG ; 16 bits of address represented in hexadecimal
193
194 IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
195
196 dec-octet = DIGIT / %x31-39 DIGIT / "1" 2DIGIT / "2" %x30-34 DIGIT / "25" %x30-35
197
198 IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
199
200 reg-name = *( unreserved / pct-encoded / sub-delims )
201
202 segment = *pchar
203 segment-nz = 1*pchar
204
205 pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
206 unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
207 pct-encoded = "%" HEXDIG HEXDIG
208 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
209 ```
210
211 The scheme and host are case insensitive and normally provided in lowercase.
212 All other components are case sensitive. (RFC7230 2.7.3)
213
214 Unknown schemes must be rejected with a 400 status code and the
215 closing of the connection. Because only a fixed number of schemes
216 are allowed, it is not necessary to limit its length.
217
218 The scheme provided with the request must be dropped. The effective
219 scheme is either resolved from configuration or is "https" when on
220 a TLS connection and "http" otherwise. (RFC7230 5.5)
221
222 An authority component with a userinfo component (and its
223 "@" delimiter) is invalid. The request must be rejected with
224 a 400 status code and the closing of the connection. (RFC7230 2.7.1)
225
226 A URI with a missing host identifier is invalid. The request must
227 be rejected with a 400 status code and the closing of the connection. (RFC7230 2.7.1)
228
229 The maximum length for an IPv4address is 15 characters. No
230 configurable limit is necessary.
231
232 The maximum length for an IPv6address is 47 characters. No
233 configurable limit is necessary.
234
235 The maximum length for the reg-name component must be subject
236 to a configurable limit. A good default is 255 characters. (RFC3986 3.2.2, RFC1034 3.1)
237
238 It is not possible to distinguish between an IPv4address and
239 a reg-name before reaching the end of the string, therefore
240 the length limit for IPv4address must be ignored until that
241 point.
242
243 The maximum length for the port component is 5. No configurable
244 limit is necessary.
245
246 The authority is sent both in the URI and in the host header.
247 The authority from the URI must be dropped, and the host header
248 must be used instead. (RFC7230 5.5)
249
250 The path always starts with "/" and ends with either "?", "#"
251 or the end of the URI. (RFC3986 3.3)
252
253 An empty path component is equivalent to "/". (RFC7230 2.7.3)
254
255 The query starts with "?" and ends with "#" or the end of the URI. (RFC3986 3.4)
256
257 The path and query must be subject to a configurable limit.
258 This limit must be at least as high as what the server generates.
259 A good default would be 8000 characters. (RFC7230 2.5, RFC7230 3.1.1)
260
261 A request with a too long component of absolute-form must be rejected with
262 a 414 status code and the closing of the connection. (RFC7230 3.1.1)
263
264 : authority-form
265
266 When the method is CONNECT, authority-form must be used. This
267 form does not apply to any other methods which must reject the
268 request with a 400 status code and the closing of the connection. (RFC7230 5.3.3)
269
270 ```
271 authority-form = authority
272 authority = host [ ":" port ]
273 host = IP-literal / IPv4address / reg-name
274 port = *DIGIT
275
276 IP-literal = "[" ( IPv6address / IPvFuture ) "]"
277
278 IPv6address = 6( h16 ":" ) ls32
279 / "::" 5( h16 ":" ) ls32
280 / [ h16 ] "::" 4( h16 ":" ) ls32
281 / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
282 / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
283 / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
284 / [ *4( h16 ":" ) h16 ] "::" ls32
285 / [ *5( h16 ":" ) h16 ] "::" h16
286 / [ *6( h16 ":" ) h16 ] "::"
287
288 ls32 = ( h16 ":" h16 ) / IPv4address ; least-significant 32 bits of address
289 h16 = 1*4HEXDIG ; 16 bits of address represented in hexadecimal
290
291 IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
292
293 dec-octet = DIGIT / %x31-39 DIGIT / "1" 2DIGIT / "2" %x30-34 DIGIT / "25" %x30-35
294
295 IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
296
297 reg-name = *( unreserved / pct-encoded / sub-delims )
298
299 unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
300 pct-encoded = "%" HEXDIG HEXDIG
301 sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
302 ```
303
304 An authority component with a userinfo component (and its
305 "@" delimiter) is invalid. The request must be rejected with
306 a 400 status code and the closing of the connection. (RFC7230 2.7.1)
307
308 The maximum length for an IPv4address is 15 characters. No
309 configurable limit is necessary.
310
311 The maximum length for an IPv6address is 47 characters. No
312 configurable limit is necessary.
313
314 The maximum length for the reg-name component must be subject
315 to a configurable limit. A good default is 255 characters. (RFC3986 3.2.2, RFC1034 3.1)
316
317 It is not possible to distinguish between an IPv4address and
318 a reg-name before reaching the end of the string, therefore
319 the length limit for IPv4address must be ignored until that
320 point.
321
322 The maximum length for the port component is 5. No configurable
323 limit is necessary.
324
325 A request with a too long component of authority-form must be rejected with
326 a 414 status code and the closing of the connection. (RFC7230 3.1.1)
327
328 The authority is either resolved from configuration or is taken
329 directly from authority-form. (RFC7230 5.5)
330
331 The path and query are empty when using authority-form. (RFC7230 5.5)
332
333 : asterisk-form
334
335 asterisk-form is used for server-wide OPTIONS requests.
336 It is invalid with any other methods which must reject the
337 request with a 400 status code and the closing of the connection. (RFC7230 5.3.4)
338
339 ```
340 asterisk-form = "*"
341 ```
342
343 The asterisk-form always has a length of 1. No configurable limit
344 is necessary.
345
346 The authority is empty when using asterisk-form.
347
348 The path and query are empty when using asterisk-form. (RFC7230 5.5)
349
350 :: Between request-target and version
351
352 A request that uses anything other than SP as separator between
353 the request-target and the version must be rejected with a 400
354 status code and the closing of the connection. (RFC7230 3.1.1, RFC7230 3.5)
355
356 :: Request version
357
358 ```
359 version = "HTTP/1.0" / "HTTP/1.1"
360 ```
361
362 Any version number other than HTTP/1.0 or HTTP/1.1 must be
363 rejected by a server or intermediary with a 505 status code. (RFC7230 2.6, RFC7230 A.2)
364
365 A request that has any whitespace or characters different than
366 CRLF following the version must be rejected with a 400 status
367 code and the closing of the connection. (RFC7230 3.1.1)
368
369 :: Request headers
370
371 ```
372 headers = *( header-field CRLF ) CRLF
373 header-field = field-name ":" OWS field-value OWS
374
375 field-name = token
376 field-value = *( SP / HTAB / %21-7E / %80-FF )
377
378 OWS = *( SP / HTAB )
379 ```
380
381 The header field name is case insensitive. (RFC7230 3.2)
382
383 HTTP/2 requires header field names to be lowercase. It is
384 perfectly acceptable for a server supporting both to convert
385 HTTP/1.1 header names to lowercase when they are received. (draft-ietf-httpbis-http2-15 8.1.2.1)
386
387 Messages that contain whitespace before the header name must
388 be rejected with a 400 status code and the closing of the
389 connection. (RFC7230 3.2.4)
390
391 Messages that contain whitespace between the header name and
392 colon must be rejected with a 400 status code and the closing
393 of the connection. (RFC7230 3.2.4)
394
395 The header name must be subject to a configurable limit. A
396 good default is 50 characters, well above the longest registered
397 header. Such a request must be rejected with a 431 status code
398 and the closing of the connection. (RFC7230 3.2.5, RFC6585 5, IANA Message Headers registry)
399
400 The header value and the optional whitespace around it must be
401 subject to a configurable limit. There is no recommendations
402 for the default. 4096 characters is known to work well. Such
403 a request must be rejected with a 431 status code and the closing
404 of the connection. (RFC7230 3.2.5, RFC6585 5)
405
406 Optional whitespace before and after the header value is not
407 part of the value and must be dropped.
408
409 The order of header fields with differing names is not significant. (RFC7230 3.2.2)
410
411 The normal procedure for parsing headers is to read each header
412 field into a hash table by field name until the empty line. (RFC7230 3)
413
414 Requests with duplicate content-length or host headers must be rejected
415 with a 400 status code and the closing of the connection. (RFC7230 3.3.2)
416
417 Other duplicate header fields must be combined by inserting a comma
418 between the values in the order they were received. (RFC7230 3.2.2)
419
420 Duplicate header field names are only allowed when their value is
421 a comma-separated list. In practice there is no need to perform
422 a check while reading the headers as the value will become invalid
423 and the error can be handled while parsing the header later on. (RFC7230 3.2.2)
424
425 The request must not be processed until all headers have arrived. (RFC7230 3.2.2)
426
427 The number of headers allowed in a request must be subject to
428 a configurable limit. There is no recommendations for the default.
429 100 headers is known to work well. Such a request must be rejected
430 with a 431 status code and the closing of the connection. (RFC7230 3.2.5, RFC6585 5)
431
432 When parsing header field values, the server must ignore empty
433 list elements, and not count those as the count of elements present. (RFC7230 7)
434
435 The information in the via header is largely unreliable. (RFC7230 5.7.1)
436
437 :: Request body
438
439 ```
440 message-body = *OCTET
441 ```
442
443 The message body is the octets after decoding any transfer
444 codings. (RFC7230 3.3)
445
446 A request has a message body only if it includes a transfer-encoding
447 header or a non-zero content-length header. (RFC7230 3.3)
448
449 ```
450 Transfer-Encoding = 1#transfer-coding
451
452 transfer-coding = "chunked" / "compress" / "deflate" / "gzip" / transfer-extension
453 transfer-extension = token *( OWS ";" OWS transfer-parameter )
454 transfer-parameter = token BWS "=" BWS ( token / quoted-string )
455 ```
456
457 The transfer-coding is case insensitive. (RFC7230 4)
458
459 There are no known other transfer-extension with the exception of
460 deprecated aliases "x-compress" and "x-gzip". (IANA HTTP Transfer Coding Registry,
461 RFC7230 4.2.1, RFC7230 4.2.3, RFC7230 8.4.2)
462
463 A server must be able to handle at least chunked transfer-encoding.
464 This is also the only coding that sees widespread use. (RFC7230 3.3.1, RFC7230 4.1)
465
466 Messages encoded more than once with chunked transfer-encoding
467 must be rejected with a 400 status code and the closing of the
468 connection. (RFC7230 3.3.1)
469
470 Messages where chunked, when present, is not the last
471 transfer-encoding must be rejected with a 400 status code
472 and the closing of the connection. (RFC7230 3.3.3)
473
474 Some non-conformant implementations send the "deflate" compressed
475 data without the zlib wrapper. (RFC7230 4.2.2)
476
477 Messages encoded with a transfer-encoding the server does not
478 understand must be rejected with a 501 status code and the
479 closing of the connection. (RFC7230 3.3.1)
480
481 A server can reject requests with a body and no content-length
482 header with a 411 status code. (RFC7230 3.3.3)
483
484 ```
485 Content-Length = 1*DIGIT
486 ```
487
488 A request with an invalid content-length header must be rejected
489 with a 400 status code and the closing of the connection. (RFC7230 3.3.3)
490
491 The content-length header ranges from 0 to infinity. Requests
492 with a message body too large must be rejected with a 413 status
493 code and the closing of the connection. (RFC7230 3.3.2)
494
495 When a message includes both transfer-encoding and content-length
496 headers, the content-length header must be removed before processing
497 the request. (RFC7230 3.3.3)
498
499 If a socket error occurs while reading the body the server
500 must send a 400 status code response and close the connection. (RFC7230 3.3.3, RFC7230 3.4)
501
502 If a timeout occurs while reading the body the server must
503 send a 408 status code response and close the connection. (RFC7230 3.3.3, RFC7230 3.4)
504
505 : Body length
506
507 The length of a message with a transfer-encoding header can
508 only be determined on decoding completion. (RFC7230 3.3.3)
509
510 The length of a message with a content-length header is
511 the numeric value in octets found in the header. (RFC7230 3.3.3)
512
513 A message with no transfer-encoding or content-length header
514 has a body length of 0. (RFC7230 3.3.3)
515
516 : Chunked transfer-encoding
517
518 ```
519 chunked-body = *chunk last-chunk trailer-part CRLF
520
521 chunk = chunk-size [ chunk-ext ] CRLF chunk-data CRLF
522 chunk-size = 1*HEXDIG
523 chunk-data = 1*OCTET ; a sequence of chunk-size octets
524
525 last-chunk = 1*("0") [ chunk-ext ] CRLF
526 ```
527
528 The chunk-size field is a string of hex digits indicating the size of
529 the chunk-data in octets.
530
531 ```
532 chunk-ext = *( ";" chunk-ext-name [ "=" chunk-ext-val ] )
533 chunk-ext-name = token
534 chunk-ext-val = token / quoted-string
535 ```
536
537 Unknown chunk extensions must be ignored. (RFC7230 4.1.1)
538
539 The chunk-size line length must be subject to configuration.
540 There are no recommended defaults, although 100 octets should work.
541 Requests with a too long line must be rejected with a 400 status
542 code and the closing of the connection.
543
544 ```
545 trailer-part = *( header-field CRLF )
546 ```
547
548 Trailing headers must not include transfer-encoding, content-length,
549 host, cache-control, expect, max-forwards, pragma, range, te,
550 if-match, if-none-match, if-modified-since, if-unmodified-since,
551 if-range, www-authenticate, authorization, proxy-authenticate,
552 proxy-authorization, age, cache-control, expires, date, location,
553 retry-after, vary, warning, content-encoding, content-type,
554 content-range, or trailer. (RFC7230 4.1.2)
555
556 Trailer headers can be ignored safely. (RFC7230 4.1.2)
557
558 When trailer headers are processed, invalid headers must be ignored.
559 Valid headers must be added to the list of headers of the request. (RFC7230 4.1.2)
560
561 The number of trailer headers must be subject to configuration.
562 There is no known recommendations for the default. A value of 10
563 should cover most cases. Requests with too many trailer headers
564 must be rejected with a 431 status code and the closing of the
565 connection. (RFC6585 5)
566
567 Upon completion of chunk decoding the server must add a content-length
568 header with the value set to the total length of data read. (RFC7230 4.1.3)
569
570 Upon completion of chunk decoding the server must remove "chunked"
571 from the transfer-encoding header. This header must be removed if
572 it becomes empty following this removal. (RFC7230 4.1.3)
573
574 Upon completion of chunk decoding the server must remove the trailer
575 header from the list of headers. (RFC7230 4.1.3)
576
577 ```
578 Trailer = 1#field-name
579 ```
580
581 The trailer header can be used to list the headers found in the
582 trailer. A server must have the option of ignoring trailer headers
583 that were not listed in the trailer header. (RFC7230 4.4)
584
585 The trailer header must be listed in the connection header field.
586 Trailers must be ignored otherwise.
587
588 :: Connection management
589
590 Never assume any two requests on a single connection come
591 from the same user agent. (RFC7230 2.3)
592
593 ```
594 Connection = 1#token ; case-insensitive
595 ```
596
597 The connection token is either case insensitive "close", "keep-alive"
598 or a header field name.
599
600 There are no corresponding "close" or "keep-alive" headers. (RFC7230 8.1, RFC7230 A.2)
601
602 The connection header is valid only for the immediate connection,
603 alongside any header field it lists. (RFC7230 6.1)
604
605 The server must determine if the connection is persistent for
606 every message received by looking at the connection header and
607 HTTP version. (RFC7230 6.3)
608
609 HTTP/1.1 requests with no "close" option and HTTP/1.0 with the
610 "keep-alive" option indicate the connection will persist. (RFC7230 6.1, RFC7230 6.3)
611
612 HTTP/1.1 requests with the "close" option and HTTP/1.0 with no
613 "keep-alive" option indicate the connection will be closed
614 upon reception of the response by the client. (RFC7230 6.1, RFC7230 6.3)
615
616 The maximum number of requests sent using a persistent connection
617 must be subject to configuration. The connection must be closed
618 when the limit is reached. (RFC7230 6.3)
619
620 A server that doesn't want to read the entire body of a message
621 must close the connection, if possible after sending the "close"
622 connection option in the response. (RFC7230 6.3)
623
624 A server can receive more than one request before any response
625 is sent. This is called pipelining. The requests can be processed
626 in parallel if they all have safe methods. Responses must be sent
627 in the same order as the requests. (RFC7230 6.3.2)
628
629 The server must reject abusive traffic by closing the connection.
630 Abusive traffic can come from the form of too many requests in a
631 given amount of time, or too many concurrent connections. Limits
632 must be subject to configuration. (RFC7230 6.4)
633
634 The server must close inactive connections. The timeout
635 must be subject to configuration. (RFC7230 6.5)
636
637 The server must monitor connections for the close signal
638 and close the socket on its end accordingly. (RFC7230 6.5)
639
640 A connection close may occur at any time. (RFC7230 6.5)
641
642 The server must not process any request after sending or
643 receiving the "close" connection option. (RFC7230 6.6)
644
645 The server must close the connection in stages to avoid the
646 TCP reset problem. The server starts by closing the write
647 side of the socket. The server then reads until it detects
648 the socket has been closed, until it can be certain its
649 last response has been received by the client, or until
650 a close or timeout occurs. The server then fully close the
651 connection. (6.6)
652
653 :: Routing
654
655 ```
656 Host = authority ; same as authority-form
657 ```
658
659 An HTTP/1.1 request that lack a host header must be rejected with
660 a 400 status code and the closing of the connection. (RFC7230 5.4)
661
662 An HTTP/1.0 request that lack a host header is valid. Behavior
663 for these requests is configuration dependent. (RFC7230 5.5)
664
665 A request with an invalid host header must be rejected with a
666 400 status code and the closing of the connection. (RFC7230 5.4)
667
668 An authority component with a userinfo component (and its
669 "@" delimiter) is invalid. The request must be rejected with
670 a 400 status code and the closing of the connection. (RFC7230 2.7.1)
671
672 When using absolute-form the URI authority component must be
673 identical to the host header. Invalid requests must be rejected
674 with a 400 status code and the closing of the connection. (RFC7230 5.4)
675
676 When using authority-form the URI authority component must be
677 identical to the host header. Invalid requests must be rejected
678 with a 400 status code and the closing of the connection.
679
680 The host header is empty when the authority component is undefined. (RFC7230 5.4)
681
682 The effective request URI can be rebuilt by concatenating scheme,
683 "://", authority, path and query components. (RFC7230 5.5)
684
685 Resources with identical URI except for the scheme component
686 must be treated as different. (RFC7230 2.7.2)
687
688 :: Response
689
690 A server can send more than one response per request only when a
691 1xx response is sent preceding the final response. (RFC7230 5.6)
692
693 A server that does parallel pipelining must send responses in the
694 same order as the requests came in. (RFC7230 5.6)
695
696 ```
697 HTTP-response = status-line *( header-field CRLF ) CRLF [ message-body ]
698 ```
699
700 The response format must be followed strictly.
701
702 ```
703 status-line = HTTP-version SP status-code SP reason-phrase CRLF
704 status-code = 3DIGIT
705 reason-phrase = *( HTAB / SP / VCHAR / obs-text )
706 ```
707
708 A server must send its own version. (RFC7230 2.6)
709
710 An HTTP/1.1 server may send an HTTP/1.0 version for compatibility purposes. (RFC7230 2.6)
711
712 RFC6585 defines additional status code a server can use to reject
713 messages. (RFC7230 9.3, RFC6585)
714
715 :: Response headers
716
717 In responses, OWS must be generated as SP or not generated
718 at all. RWS must be generated as SP. BWS must not be
719 generated. (RFC7230 3.2.3)
720
721 ```
722 header-field = field-name ":" SP field-value
723
724 field-name = token ; case-insensitive
725 field-value = *( SP / %21-7E / %80-FF )
726 ```
727
728 In quoted-string found in field-value, quoted-pair must only be
729 used for DQUOTE and backslash. (RFC7230 3.2.6)
730
731 The server must not generate comments in header values.
732
733 HTTP header values must use US-ASCII encoding and must only send
734 printable characters or SP. (RFC7230 3.2.4, RFC7230 9.4)
735
736 The server must not generate empty list elements in headers. (RFC7230 7)
737
738 When encoding an URI as part of a response, only characters that
739 are reserved need to be percent-encoded. (RFC7230 2.7.3)
740
741 The set-cookie header must be handled as a special case. There
742 must be exactly one set-cookie header field per cookie. (RFC7230 3.2.2)
743
744 The server must list headers for or about the immediate connection
745 in the connection header field. (RFC7230 6.1)
746
747 A server that does not support persistent connections must
748 send "close" in every non-1xx response. (RFC7230 6.1)
749
750 A server must not send a "close" connection option
751 in 1xx responses. (RFC7230 6.1)
752
753 The "close" connection must be sent in a message when the
754 sender knows it will close the connection after fully sending
755 the response. (RFC7230 6.6)
756
757 A server must close the connection after sending or
758 receiving a "close" once the response has been sent. (RFC7230 6.6)
759
760 A server must send a "close" in a response to a request
761 containing a "close". (RFC7230 6.6)
762
763 :: Response body
764
765 Responses to HEAD requests never include a message body. (RFC7230 3.3)
766
767 2xx responses to CONNECT requests never include a message
768 body. (RFC7230 3.3)
769
770 1xx, 204 and 304 responses never include a message body. (RFC7230 3.3)
771
772 Responses to HEAD requests and 304 responses can include a
773 content-length or transfer-encoding header. Their value must
774 be the same as if the request was an unconditional GET. (RFC7230 3.3, RFC7230 3.3.1, RFC7230 3.3.2)
775
776 1xx, 204 responses and 2xx responses to CONNECT requests must
777 not include a content-length or transfer-encoding header. (RFC7230 3.3.1, RFC7230 3.3.2)
778
779 ```
780 message-body = *OCTET
781 ```
782
783 The message body is the octets after decoding any transfer
784 codings. (RFC7230 3.3)
785
786 When the length is known in advance, the server must send a
787 content-length header, including if the length is 0. (RFC7230 3.3.2, RFC7230 3.3.3)
788
789 When the length is not known in advance, the chunked transfer-encoding
790 must be used. (RFC7230 3.3.2, RFC7230 3.3.3)
791
792 For compatibility purposes a server can send no content-length or
793 transfer-encoding header. In this case the connection must be
794 closed after the response has been sent fully. (RFC7230 3.3.2, RFC7230 3.3.3)
795
796 The content-length header must not be sent when a transfer-encoding
797 header already exists. (RFC7230 3.3.2)
798
799 The server must not apply the chunked transfer-encoding more than
800 once. (RFC7230 3.3.1)
801
802 The server must apply the chunked transfer-encoding last. (RFC7230 3.3.1)
803
804 The transfer-encoding header must not be sent in responses to
805 HTTP/1.0 requests, or in responses that use the HTTP/1.0 version.
806 No transfer codings must be applied in these cases. (RFC7230 3.3.1)
807
808 ```
809 TE = #t-codings
810
811 t-codings = "trailers" / ( transfer-coding [ t-ranking ] )
812 t-ranking = OWS ";" OWS "q=" rank
813 rank = ( "0" [ "." 0*3DIGIT ] ) / ( "1" [ "." 0*3("0") ] )
814 ```
815
816 Trailers can only be sent if the request includes a TE header
817 containing "trailers". (RFC7230 4.1.2)
818
819 The presence of "chunked" in a TE header must be ignored as it
820 is always acceptable with HTTP/1.1. (RFC7230 4.3)
821
822 A qvalue of 0 in the TE header means "not acceptable". (RFC7230 4.3)
823
824 The lack of a TE header or an empty TE header means only "chunked"
825 (with no trailers) or no transfer-encoding is acceptable. (RFC7230 4.3)
826
827 The TE header must be listed in the connection header field,
828 or must be ignored otherwise.
829
830 Trailer headers must be listed in the trailer header field value. (RFC7230 4.4)
831
832 When defined, the trailer header must also be listed in the connection header. (RFC7230 4.4)
833
834 :: Upgrade
835
836 ```
837 Upgrade = 1#protocol
838
839 protocol = protocol-name ["/" protocol-version]
840 protocol-name = token
841 protocol-version = token
842 ```
843
844 The upgrade header contains the list of protocols the
845 client wishes to upgrade to, in order of preference. (RFC7230 6.7)
846
847 The upgrade header can be safely ignored. (RFC7230 6.7)
848
849 The upgrade header must be listed under the connection header,
850 or must be ignored otherwise. (RFC7230 6.7)
851
852 A server accepting an upgrade request must send a 101 status
853 code with a upgrade header listing the protocol(s) it upgrades
854 to, in layer-ascending order. In addition the upgrade header
855 must be listed in the connection header. (RFC7230 6.7)
856
857 A server must not switch to a protocol not listed in the
858 request's upgrade header. (RFC7230 6.7)
859
860 A server that sends a 426 status code must include a upgrade
861 header listing acceptable protocols in order of preference. (RFC7230 6.7)
862
863 A server can send a upgrade header to any response to advertise
864 its support for other protocols listed in order of preference. (RFC7230 6.7)
865
866 Immediately after a server responds with a 101 status code
867 it must respond to the original request using the new protocol. (RFC7230 6.7)
868
869 A server must not switch protocols unless the original message's
870 semantics can be honored by the new protocol. OPTIONS requests
871 can be honored by any protocol. (RFC7230 6.7)
872
873 A server must ignore an upgrade header received by an HTTP/1.0
874 request. (RFC7230 6.7)
875
876 A server receiving both an upgrade header and an expect header
877 containing "100-continue" must send a 100 response before the
878 101 response. (RFC7230 6.7)
879
880 The upgrade header field cannot be used for switching the
881 connection protocol (e.g. TCP) or switching connections. (RFC7230 6.7)
882
883 :: Compatibility
884
885 A server can choose to be non-conformant to the specifications
886 for the sake of compatibility. Such behavior can be enabled
887 through configuration and/or software identification. (RFC7230 2.5)