Module: Protocol::HTTP1
- Defined in:
- lib/protocol/http1.rb,
lib/protocol/http1/body.rb,
lib/protocol/http1/error.rb,
lib/protocol/http1/version.rb,
lib/protocol/http1/body/fixed.rb,
lib/protocol/http1/connection.rb,
lib/protocol/http1/body/chunked.rb,
lib/protocol/http1/body/remainder.rb
Defined Under Namespace
Modules: Body Classes: BadHeader, BadRequest, Connection, ContentLengthError, Error, InvalidRequest, LineLengthError, ProtocolError
Constant Summary collapse
- VERSION =
"0.40.0"- CONTENT_LENGTH =
"content-length"- TRANSFER_ENCODING =
"transfer-encoding"- CHUNKED =
"chunked"- CONNECTION =
"connection"- CLOSE =
"close"- KEEP_ALIVE =
"keep-alive"- HOST =
"host"- UPGRADE =
"upgrade"- TOKEN =
HTTP/1.x request line parser:
/[!#$%&'*+\-\.\^_`|~0-9a-zA-Z]+/.freeze
- REQUEST_LINE =
/\A(#{TOKEN}) ([^\s]+) (HTTP\/\d.\d)\z/.freeze
- FIELD_NAME =
HTTP/1.x header parser:
TOKEN- OWS =
/[ \t]*/- FIELD_VALUE =
A field value is any string of characters that does not contain a null character, CR, or LF. After reflecting on the RFCs and surveying real implementations, I came to the conclusion that the RFCs are too restrictive. Most servers only check for the presence of null bytes, and obviously CR/LF characters have semantic meaning in the parser. So, I decided to follow this defacto standard, even if I'm not entirely happy with it.
/[^\0\r\n]+/.freeze
- HEADER =
/\A(#{FIELD_NAME}):#{OWS}(?:(#{FIELD_VALUE})#{OWS})?\z/.freeze
- VALID_FIELD_NAME =
/\A#{FIELD_NAME}\z/.freeze
- VALID_FIELD_VALUE =
/\A#{FIELD_VALUE}?\z/.freeze
- DEFAULT_MAXIMUM_LINE_LENGTH =
8192