Skip to content

class HTTP::Request
inherits Reference

An HTTP request.

It serves both to perform requests by an HTTP::Client and to represent requests received by an HTTP::Server.

A request always holds an IO as a body. When creating a request with a String or Bytes its body will be a IO::Memory wrapping these, and the Content-Length header will be set appropriately.

Class methods

.from_io(io, *, max_request_line_size : Int32 = HTTP::MAX_REQUEST_LINE_SIZE, max_headers_size : Int32 = HTTP::MAX_HEADERS_SIZE) : HTTP::Request | HTTP::Status | Nil

Returns a HTTP::Request instance if successfully parsed, nil on EOF or HTTP::Status otherwise.

View source

.new(method : String, resource : String, headers : Headers? = nil, body : String | Bytes | IO | Nil = nil, version = "HTTP/1.1")

View source

Methods

#body : IO?

View source

#body=(body : Nil)

View source

#body=(body : IO)

View source

#body=(body : Bytes)

View source

#body=(body : String)

View source

#content_length

View source

#content_length=(length : Int)

View source

#cookies

Returns a convenience wrapper around querying and setting cookie related headers, see HTTP::Cookies.

View source

#headers : Headers

View source

#headers=(headers : Headers)

View source

#host_with_port

Returns request host with port from headers.

View source

#hostname : String?

Extracts the hostname from Host header.

Returns nil if the Host header is missing.

If the Host header contains a port number, it is stripped off.

View source

#if_match : Array(String)?

View source

#if_none_match : Array(String)?

View source

#ignore_body?

View source

#keep_alive?

View source

#local_address : Socket::Address?

The network address of the HTTP server.

HTTP::Server will try to fill this property, and its value will have a format like "IP:port", but this format is not guaranteed. Middlewares can overwrite this value.

This property is not used by HTTP::Client.

#local_address=(local_address : Socket::Address?)

The network address of the HTTP server.

HTTP::Server will try to fill this property, and its value will have a format like "IP:port", but this format is not guaranteed. Middlewares can overwrite this value.

This property is not used by HTTP::Client.

#method : String

View source

#method=(method : String)

View source

#path

Returns the request's path component.

View source

#path=(path)

Sets request's path component.

View source

#query

Lazily parses and returns the request's query component.

View source

#query=(value)

Sets request's query component.

View source

#query_params

Returns a convenience wrapper around querying and setting query params, see URI::Params.

View source

#remote_address : Socket::Address?

The network address that sent the request to an HTTP server.

HTTP::Server will try to fill this property, and its value will have a format like "IP:port", but this format is not guaranteed. Middlewares can overwrite this value.

This property is not used by HTTP::Client.

#remote_address=(remote_address : Socket::Address?)

The network address that sent the request to an HTTP server.

HTTP::Server will try to fill this property, and its value will have a format like "IP:port", but this format is not guaranteed. Middlewares can overwrite this value.

This property is not used by HTTP::Client.

#resource

View source

#to_io(io)

View source

#version : String

View source

#version=(version : String)

View source