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
¶
(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.
.new(method : String, resource : String, headers : Headers? = nil, body : String | Bytes | IO | Nil = nil, version = "HTTP/1.1")
¶
(method : String, resource : String, headers : Headers? = nil, body : String | Bytes | IO | Nil = nil, version = "HTTP/1.1")
Methods¶
#cookies
¶
Returns a convenience wrapper around querying and setting cookie related
headers, see HTTP::Cookies
.
#hostname : String?
¶
: 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.
#local_address : Socket::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?)
¶
(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
.
#query_params
¶
Returns a convenience wrapper around querying and setting query params,
see URI::Params
.
#remote_address : Socket::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?)
¶
(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
.