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.
NOTE To use Request, you must explicitly import it with require "http/request"
Returns a HTTP::Request instance if successfully parsed, nil on EOF or HTTP::Status otherwise.
Returns a convenience wrapper around querying and setting cookie related headers, see HTTP::Cookies.
Returns a convenience wrapper to parse form params, see URI::Params.
Returns a convenience wrapper to parse form params, see URI::Params.
Returns request host with port from headers.
DEPRECATED Use headers["Host"]? instead.
Extracts the hostname from Host header.
The network address of the HTTP server.
The network address of the HTTP server.
Returns the request's path component.
Sets request's path component.
Lazily parses and returns the request's query component.
Sets request's query component.
Returns a convenience wrapper around querying and setting query params, see URI::Params.
The network address that sent the request to an HTTP server.
The network address that sent the request to an HTTP server.
Returns the underlying URI object.
Reference
Reference
Reference
Object
Object
Object
Returns a HTTP::Request instance if successfully parsed, nil on EOF or HTTP::Status otherwise.
Returns a convenience wrapper around querying and setting cookie related headers, see HTTP::Cookies.
Returns a convenience wrapper to parse form params, see URI::Params.
Returns a convenience wrapper to parse form params, see URI::Params. Returns nil in case the content type "application/x-www-form-urlencoded" is not present or the body is nil.
Returns request host with port from headers.
DEPRECATED Use headers["Host"]? instead.
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.
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.
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.
Returns a convenience wrapper around querying and setting query params, see URI::Params.
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.
Example:
class ForwarderHandler
include HTTP::Handler
def call(context)
if ip = context.request.headers["X-Real-IP"]? # When using a reverse proxy that guarantees this field.
context.request.remote_address = Socket::IPAddress.new(ip, 0)
end
call_next(context)
end
end
server = HTTP::Server.new([ForwarderHandler.new, HTTP::LogHandler.new]) This property is not used by HTTP::Client.
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.
Example:
class ForwarderHandler
include HTTP::Handler
def call(context)
if ip = context.request.headers["X-Real-IP"]? # When using a reverse proxy that guarantees this field.
context.request.remote_address = Socket::IPAddress.new(ip, 0)
end
call_next(context)
end
end
server = HTTP::Server.new([ForwarderHandler.new, HTTP::LogHandler.new]) This property is not used by HTTP::Client.
Returns the underlying URI object.
Used internally to provide the components of the request uri.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/HTTP/Request.html