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 | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 215 | ---- The correct way to do it ---- |
| 216 | |
| 217 | - one http_session |
| 218 | It is basically any transport session on which we talk HTTP. It may be TCP, |
| 219 | SSL over TCP, etc... It knows a way to talk to the client, either the socket |
| 220 | file descriptor or a direct access to the client-side buffer. It should hold |
| 221 | information about the last accessed server so that we can guarantee that the |
| 222 | same server can be used during a whole session if needed. A first version |
| 223 | without optimal support for HTTP pipelining will have the client buffers tied |
| 224 | to the http_session. It may be possible that it is not sufficient for full |
| 225 | 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] | 226 | the backend should be managed by the http transaction (http_txn), provided |
| 227 | that they are serialized. Each http_session, has 0 to N http_txn. Each |
| 228 | http_txn belongs to one and only one http_session. |
Willy Tarreau | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 229 | |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 230 | - each http_txn has 1 request message (http_req), and 0 or 1 response message |
| 231 | (http_rtr). Each of them has 1 and only one http_txn. An http_txn holds |
| 232 | informations such as the HTTP method, the URI, the HTTP version, the |
| 233 | transfer-encoding, the HTTP status, the authorization, the req and rtr |
| 234 | content-length, the timers, logs, etc... The backend and server which process |
| 235 | the request are also known from the http_txn. |
Willy Tarreau | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 236 | |
| 237 | - both request and response messages hold header and parsing informations, such |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 238 | as the parsing state, start of headers, start of message, captures, etc... |
Willy Tarreau | 1ba6a73 | 2007-01-07 12:43:29 +0100 | [diff] [blame] | 239 | |