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