# module HTTP

##
Overview

The HTTP module contains `HTTP::Client`, `HTTP::Server` and `HTTP::WebSocket` implementations.

NOTE To use `HTTP`, you must explicitly import it with `require "http"`

##
Defined in:

http.cr
http/client.cr
http/common.cr
http/content.cr
http/cookie.cr
http/cookies.cr
http/params.cr

##
Constant Summary

MAX_HEADERS_SIZE = `16384`

  Default maximum permitted combined size (in bytes) of the headers in an HTTP request.

MAX_REQUEST_LINE_SIZE = `8192`

  Default maximum permitted size (in bytes) of the request line in an HTTP request.

SUPPORTED_VERSIONS = `{"HTTP/1.0", "HTTP/1.1"}`

##
Class Method Summary

- .dequote_string(str : String) : String

  Dequotes an RFC 2616 quoted-string.

- .expect_continue?(headers : HTTP::Headers) : Bool
- .format_time(time : Time) : String

  Format a `Time` object as a `String` using the format specified as `sane-cookie-date` by RFC 6265 which is according to RFC 2616 a RFC 1123 format with explicit timezone `GMT` (interpreted as `UTC`).

- .parse_time(time_str : String) : Time | Nil

  Parse a time string using the formats specified by RFC 2616

- .quote_string(string : String, io : IO) : Nil

  Encodes a string to an RFC 2616 quoted-string.

- .quote_string(string : String) : String

  Encodes a string to an RFC 2616 quoted-string.

- .serialize_chunked_body(io : IO, body : IO) : Nil
- .serialize_headers(io, headers)

  DEPRECATED Use `HTTP::Headers#serialize` instead.

- .serialize_headers_and_string_body(io : IO, headers : HTTP::Headers, body : String) : Nil

##
Class Method Detail

def self.dequote_string(str : String) : String #

Dequotes an RFC 2616 quoted-string.

    require "http"

    quoted = %q(\"foo\\bar\")
    HTTP.dequote_string(quoted) # => %q("foo\bar")

def self.expect_continue?(headers : HTTP::Headers) : Bool #
def self.format_time(time : Time) : String #

Format a `Time` object as a `String` using the format specified as `sane-cookie-date` by RFC 6265 which is according to RFC 2616 a RFC 1123 format with explicit timezone `GMT` (interpreted as `UTC`).

    require "http"

    HTTP.format_time(Time.utc(2016, 2, 15)) # => "Mon, 15 Feb 2016 00:00:00 GMT"

Uses `Time::Format::HTTP_DATE` as formatter.

def self.parse_time(time_str : String) : Time | Nil #

Parse a time string using the formats specified by RFC 2616

    require "http"

    HTTP.parse_time("Sun, 14 Feb 2016 21:00:00 GMT")  # => "2016-02-14 21:00:00Z"
    HTTP.parse_time("Sunday, 14-Feb-16 21:00:00 GMT") # => "2016-02-14 21:00:00Z"
    HTTP.parse_time("Sun Feb 14 21:00:00 2016")       # => "2016-02-14 21:00:00Z"

Uses `Time::Format::HTTP_DATE` as parser.

def self.quote_string(string : String, io : IO) : Nil #

Encodes a string to an RFC 2616 quoted-string. Encoded string is written to io. May raise when string contains an invalid character.

    require "http"

    string = %q("foo\ bar")
    io = IO::Memory.new
    HTTP.quote_string(string, io)
    io.rewind
    io.gets_to_end # => %q(\"foo\\\ bar\")

def self.quote_string(string : String) : String #

Encodes a string to an RFC 2616 quoted-string. May raise when string contains an invalid character.

    require "http"

    string = %q("foo\ bar")
    HTTP.quote_string(string) # => %q(\"foo\\\ bar\")

def self.serialize_chunked_body(io : IO, body : IO) : Nil #
def self.serialize_headers(io, headers) #

DEPRECATED Use `HTTP::Headers#serialize` instead.

def self.serialize_headers_and_string_body(io : IO, headers : HTTP::Headers, body : String) : Nil #