module HTTP1

Nested Classes and Modules

module Body

A collection of classes for handling HTTP/1.1 request and response bodies.

class Connection

Represents a single HTTP/1.x connection, which may be used to send and receive multiple requests and responses.

class Error

The base class for all HTTP/1.x errors.

class ProtocolError

The protocol was violated in some way, e.g. trying to write a request while reading a response.

class LineLengthError

The request line was too long.

class BadRequest

The request was not able to be parsed correctly, or failed some kind of validation.

class BadHeader

A header name or value was invalid, e.g. contains invalid characters.

class InvalidRequest

Indicates that the request is invalid for some reason, e.g. syntax error, invalid headers, etc.

class ContentLengthError

The 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.