module HTTP1
Nested Classes and Modules
module BodyA collection of classes for handling HTTP/1.1 request and response bodies.
class ConnectionRepresents a single HTTP/1.x connection, which may be used to send and receive multiple requests and responses.
class ErrorThe base class for all HTTP/1.x errors.
class ProtocolErrorThe protocol was violated in some way, e.g. trying to write a request while reading a response.
class LineLengthErrorThe request line was too long.
class BadRequestThe request was not able to be parsed correctly, or failed some kind of validation.
class BadHeaderA header name or value was invalid, e.g. contains invalid characters.
class InvalidRequestIndicates that the request is invalid for some reason, e.g. syntax error, invalid headers, etc.
class ContentLengthErrorThe specified content length and the given content's length do not match.
Definitions
TOKEN = /[!#$%&'*+\-\.\^_`|~0-9a-zA-Z]+/.freeze
HTTP/1.x request line parser:
FIELD_NAME = TOKEN
HTTP/1.x header parser:
FIELD_VALUE = /[^\0\r\n]+/.freeze
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.