Willy Tarreau | 58f10d7 | 2006-12-04 02:26:12 +0100 | [diff] [blame] | 1 | --- Relevant portions of RFC2616 --- |
| 2 | |
| 3 | OCTET = <any 8-bit sequence of data> |
| 4 | CHAR = <any US-ASCII character (octets 0 - 127)> |
| 5 | UPALPHA = <any US-ASCII uppercase letter "A".."Z"> |
| 6 | LOALPHA = <any US-ASCII lowercase letter "a".."z"> |
| 7 | ALPHA = UPALPHA | LOALPHA |
| 8 | DIGIT = <any US-ASCII digit "0".."9"> |
| 9 | CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)> |
| 10 | CR = <US-ASCII CR, carriage return (13)> |
| 11 | LF = <US-ASCII LF, linefeed (10)> |
| 12 | SP = <US-ASCII SP, space (32)> |
| 13 | HT = <US-ASCII HT, horizontal-tab (9)> |
| 14 | <"> = <US-ASCII double-quote mark (34)> |
| 15 | CRLF = CR LF |
| 16 | LWS = [CRLF] 1*( SP | HT ) |
| 17 | TEXT = <any OCTET except CTLs, but including LWS> |
| 18 | HEX = "A" | "B" | "C" | "D" | "E" | "F" |
| 19 | | "a" | "b" | "c" | "d" | "e" | "f" | DIGIT |
| 20 | separators = "(" | ")" | "<" | ">" | "@" |
| 21 | | "," | ";" | ":" | "\" | <"> |
| 22 | | "/" | "[" | "]" | "?" | "=" |
| 23 | | "{" | "}" | SP | HT |
| 24 | token = 1*<any CHAR except CTLs or separators> |
| 25 | |
| 26 | quoted-pair = "\" CHAR |
| 27 | ctext = <any TEXT excluding "(" and ")"> |
| 28 | qdtext = <any TEXT except <">> |
| 29 | quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) |
| 30 | comment = "(" *( ctext | quoted-pair | comment ) ")" |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | 4 HTTP Message |
| 37 | 4.1 Message Types |
| 38 | |
| 39 | HTTP messages consist of requests from client to server and responses from |
| 40 | server to client. Request (section 5) and Response (section 6) messages use the |
| 41 | generic message format of RFC 822 [9] for transferring entities (the payload of |
| 42 | the message). Both types of message consist of : |
| 43 | |
| 44 | - a start-line |
| 45 | - zero or more header fields (also known as "headers") |
| 46 | - an empty line (i.e., a line with nothing preceding the CRLF) indicating the |
| 47 | end of the header fields |
| 48 | - and possibly a message-body. |
| 49 | |
| 50 | |
| 51 | HTTP-message = Request | Response |
| 52 | |
| 53 | start-line = Request-Line | Status-Line |
| 54 | generic-message = start-line |
| 55 | *(message-header CRLF) |
| 56 | CRLF |
| 57 | [ message-body ] |
| 58 | |
| 59 | In the interest of robustness, servers SHOULD ignore any empty line(s) received |
| 60 | where a Request-Line is expected. In other words, if the server is reading the |
| 61 | protocol stream at the beginning of a message and receives a CRLF first, it |
| 62 | should ignore the CRLF. |
| 63 | |
| 64 | |
| 65 | 4.2 Message headers |
| 66 | |
| 67 | - Each header field consists of a name followed by a colon (":") and the field |
| 68 | value. |
| 69 | - Field names are case-insensitive. |
| 70 | - The field value MAY be preceded by any amount of LWS, though a single SP is |
| 71 | preferred. |
| 72 | - Header fields can be extended over multiple lines by preceding each extra |
| 73 | line with at least one SP or HT. |
| 74 | |
| 75 | |
| 76 | message-header = field-name ":" [ field-value ] |
| 77 | field-name = token |
| 78 | field-value = *( field-content | LWS ) |
| 79 | field-content = <the OCTETs making up the field-value and consisting of |
| 80 | either *TEXT or combinations of token, separators, and |
| 81 | quoted-string> |
| 82 | |
| 83 | |
| 84 | The field-content does not include any leading or trailing LWS occurring before |
| 85 | the first non-whitespace character of the field-value or after the last |
| 86 | non-whitespace character of the field-value. Such leading or trailing LWS MAY |
| 87 | be removed without changing the semantics of the field value. Any LWS that |
| 88 | occurs between field-content MAY be replaced with a single SP before |
| 89 | interpreting the field value or forwarding the message downstream. |
| 90 | |
| 91 | |
| 92 | => format des headers = 1*(CHAR & !ctl & !sep) ":" *(OCTET & (!ctl | LWS)) |
| 93 | => les regex de matching de headers s'appliquent sur field-content, et peuvent |
| 94 | utiliser field-value comme espace de travail (mais de préférence après le |
| 95 | premier SP). |
| 96 | |
| 97 | (19.3) The line terminator for message-header fields is the sequence CRLF. |
| 98 | However, we recommend that applications, when parsing such headers, recognize |
| 99 | a single LF as a line terminator and ignore the leading CR. |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | message-body = entity-body |
| 106 | | <entity-body encoded as per Transfer-Encoding> |
| 107 | |
| 108 | |
| 109 | |
| 110 | 5 Request |
| 111 | |
| 112 | Request = Request-Line |
| 113 | *(( general-header |
| 114 | | request-header |
| 115 | | entity-header ) CRLF) |
| 116 | CRLF |
| 117 | [ message-body ] |
| 118 | |
| 119 | |
| 120 | |
| 121 | 5.1 Request line |
| 122 | |
| 123 | The elements are separated by SP characters. No CR or LF is allowed except in |
| 124 | the final CRLF sequence. |
| 125 | |
| 126 | Request-Line = Method SP Request-URI SP HTTP-Version CRLF |
| 127 | |
| 128 | (19.3) Clients SHOULD be tolerant in parsing the Status-Line and servers |
| 129 | tolerant when parsing the Request-Line. In particular, they SHOULD accept any |
| 130 | amount of SP or HT characters between fields, even though only a single SP is |
| 131 | required. |
| 132 | |
| 133 | 4.5 General headers |
| 134 | Apply to MESSAGE. |
| 135 | |
| 136 | general-header = Cache-Control |
| 137 | | Connection |
| 138 | | Date |
| 139 | | Pragma |
| 140 | | Trailer |
| 141 | | Transfer-Encoding |
| 142 | | Upgrade |
| 143 | | Via |
| 144 | | Warning |
| 145 | |
| 146 | General-header field names can be extended reliably only in combination with a |
| 147 | change in the protocol version. However, new or experimental header fields may |
| 148 | be given the semantics of general header fields if all parties in the |
| 149 | communication recognize them to be general-header fields. Unrecognized header |
| 150 | fields are treated as entity-header fields. |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | 5.3 Request Header Fields |
| 156 | |
| 157 | The request-header fields allow the client to pass additional information about |
| 158 | the request, and about the client itself, to the server. These fields act as |
| 159 | request modifiers, with semantics equivalent to the parameters on a programming |
| 160 | language method invocation. |
| 161 | |
| 162 | request-header = Accept |
| 163 | | Accept-Charset |
| 164 | | Accept-Encoding |
| 165 | | Accept-Language |
| 166 | | Authorization |
| 167 | | Expect |
| 168 | | From |
| 169 | | Host |
| 170 | | If-Match |
| 171 | | If-Modified-Since |
| 172 | | If-None-Match |
| 173 | | If-Range |
| 174 | | If-Unmodified-Since |
| 175 | | Max-Forwards |
| 176 | | Proxy-Authorization |
| 177 | | Range |
| 178 | | Referer |
| 179 | | TE |
| 180 | | User-Agent |
| 181 | |
| 182 | Request-header field names can be extended reliably only in combination with a |
| 183 | change in the protocol version. However, new or experimental header fields MAY |
| 184 | be given the semantics of request-header fields if all parties in the |
| 185 | communication recognize them to be request-header fields. Unrecognized header |
| 186 | fields are treated as entity-header fields. |
| 187 | |
| 188 | |
| 189 | |
| 190 | 7.1 Entity header fields |
| 191 | |
| 192 | Entity-header fields define metainformation about the entity-body or, if no |
| 193 | body is present, about the resource identified by the request. Some of this |
| 194 | metainformation is OPTIONAL; some might be REQUIRED by portions of this |
| 195 | specification. |
| 196 | |
| 197 | entity-header = Allow |
| 198 | | Content-Encoding |
| 199 | | Content-Language |
| 200 | | Content-Length |
| 201 | | Content-Location |
| 202 | | Content-MD5 |
| 203 | | Content-Range |
| 204 | | Content-Type |
| 205 | | Expires |
| 206 | | Last-Modified |
| 207 | | extension-header |
| 208 | extension-header = message-header |
| 209 | |
| 210 | The extension-header mechanism allows additional entity-header fields to be |
| 211 | defined without changing the protocol, but these fields cannot be assumed to be |
| 212 | recognizable by the recipient. Unrecognized header fields SHOULD be ignored by |
| 213 | the recipient and MUST be forwarded by transparent proxies. |
| 214 | |
Willy Tarreau | 2f1feb9 | 2012-01-07 23:58:54 +0100 | [diff] [blame] | 215 | ---------------------------------- |
| 216 | |
| 217 | The format of Request-URI is defined by RFC3986 : |
| 218 | |
| 219 | URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] |
| 220 | |
| 221 | hier-part = "//" authority path-abempty |
| 222 | / path-absolute |
| 223 | / path-rootless |
| 224 | / path-empty |
| 225 | |
| 226 | URI-reference = URI / relative-ref |
| 227 | |
| 228 | absolute-URI = scheme ":" hier-part [ "?" query ] |
| 229 | |
| 230 | relative-ref = relative-part [ "?" query ] [ "#" fragment ] |
| 231 | |
| 232 | relative-part = "//" authority path-abempty |
| 233 | / path-absolute |
| 234 | / path-noscheme |
| 235 | / path-empty |
| 236 | |
| 237 | scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) |
| 238 | |
| 239 | authority = [ userinfo "@" ] host [ ":" port ] |
| 240 | userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) |
| 241 | host = IP-literal / IPv4address / reg-name |
| 242 | port = *DIGIT |
| 243 | |
| 244 | IP-literal = "[" ( IPv6address / IPvFuture ) "]" |
| 245 | |
| 246 | IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) |
| 247 | |
| 248 | IPv6address = 6( h16 ":" ) ls32 |
| 249 | / "::" 5( h16 ":" ) ls32 |
| 250 | / [ h16 ] "::" 4( h16 ":" ) ls32 |
| 251 | / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 |
| 252 | / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 |
| 253 | / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 |
| 254 | / [ *4( h16 ":" ) h16 ] "::" ls32 |
| 255 | / [ *5( h16 ":" ) h16 ] "::" h16 |
| 256 | / [ *6( h16 ":" ) h16 ] "::" |
| 257 | |
| 258 | h16 = 1*4HEXDIG |
| 259 | ls32 = ( h16 ":" h16 ) / IPv4address |
| 260 | IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet |
| 261 | dec-octet = DIGIT ; 0-9 |
| 262 | / %x31-39 DIGIT ; 10-99 |
| 263 | / "1" 2DIGIT ; 100-199 |
| 264 | / "2" %x30-34 DIGIT ; 200-249 |
| 265 | / "25" %x30-35 ; 250-255 |
| 266 | |
| 267 | reg-name = *( unreserved / pct-encoded / sub-delims ) |
| 268 | |
| 269 | path = path-abempty ; begins with "/" or is empty |
| 270 | / path-absolute ; begins with "/" but not "//" |
| 271 | / path-noscheme ; begins with a non-colon segment |
| 272 | / path-rootless ; begins with a segment |
| 273 | / path-empty ; zero characters |
| 274 | |
| 275 | path-abempty = *( "/" segment ) |
| 276 | path-absolute = "/" [ segment-nz *( "/" segment ) ] |
| 277 | path-noscheme = segment-nz-nc *( "/" segment ) |
| 278 | path-rootless = segment-nz *( "/" segment ) |
| 279 | path-empty = 0<pchar> |
| 280 | |
| 281 | segment = *pchar |
| 282 | segment-nz = 1*pchar |
| 283 | segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) |
| 284 | ; non-zero-length segment without any colon ":" |
| 285 | |
| 286 | pchar = unreserved / pct-encoded / sub-delims / ":" / "@" |
| 287 | |
| 288 | query = *( pchar / "/" / "?" ) |
| 289 | |
| 290 | fragment = *( pchar / "/" / "?" ) |
| 291 | |
| 292 | pct-encoded = "%" HEXDIG HEXDIG |
| 293 | |
| 294 | unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" |
| 295 | reserved = gen-delims / sub-delims |
| 296 | gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" |
| 297 | sub-delims = "!" / "$" / "&" / "'" / "(" / ")" |
| 298 | / "*" / "+" / "," / ";" / "=" |
| 299 | |
| 300 | => so the list of allowed characters in a URI is : |
| 301 | |
| 302 | uri-char = unreserved / gen-delims / sub-delims / "%" |
| 303 | = ALPHA / DIGIT / "-" / "." / "_" / "~" |
| 304 | / ":" / "/" / "?" / "#" / "[" / "]" / "@" |
| 305 | / "!" / "$" / "&" / "'" / "(" / ")" / |
| 306 | / "*" / "+" / "," / ";" / "=" / "%" |
| 307 | |
| 308 | Note that non-ascii characters are forbidden ! Spaces and CTL are forbidden. |
| 309 | Unfortunately, some products such as Apache allow such characters :-/ |
| 310 | |
Willy Tarreau | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 311 | ---- The correct way to do it ---- |
| 312 | |
| 313 | - one http_session |
| 314 | It is basically any transport session on which we talk HTTP. It may be TCP, |
| 315 | SSL over TCP, etc... It knows a way to talk to the client, either the socket |
| 316 | file descriptor or a direct access to the client-side buffer. It should hold |
| 317 | information about the last accessed server so that we can guarantee that the |
| 318 | same server can be used during a whole session if needed. A first version |
| 319 | without optimal support for HTTP pipelining will have the client buffers tied |
| 320 | to the http_session. It may be possible that it is not sufficient for full |
| 321 | pipelining, but this will need further study. The link from the buffers to |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 322 | the backend should be managed by the http transaction (http_txn), provided |
| 323 | that they are serialized. Each http_session, has 0 to N http_txn. Each |
| 324 | http_txn belongs to one and only one http_session. |
Willy Tarreau | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 325 | |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 326 | - each http_txn has 1 request message (http_req), and 0 or 1 response message |
| 327 | (http_rtr). Each of them has 1 and only one http_txn. An http_txn holds |
Michael Prokop | 60ce0ef | 2022-12-09 12:28:46 +0100 | [diff] [blame] | 328 | information such as the HTTP method, the URI, the HTTP version, the |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 329 | transfer-encoding, the HTTP status, the authorization, the req and rtr |
| 330 | content-length, the timers, logs, etc... The backend and server which process |
| 331 | the request are also known from the http_txn. |
Willy Tarreau | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 332 | |
Michael Prokop | 60ce0ef | 2022-12-09 12:28:46 +0100 | [diff] [blame] | 333 | - both request and response messages hold header and parsing information, such |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 334 | as the parsing state, start of headers, start of message, captures, etc... |
Willy Tarreau | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 335 | |