data HTTP::Server::Request(method: String, target: String, path: String, query: String, version: String, headers: HTTP::Headers, body: HTTP::Body, remote_address: Socket::Address?, params: Hash[String, String], proxies: HTTP::Proxies, trusted: Bool, tls: Bool)
A request, as the server read it or as a test builds it
(HTTP::Server::Request.get). A data value: with makes a
changed copy. It is not Shareable, since its Body is not: copy the
fields a task needs out of it before spawning one.
req = HTTP::Server::Request.get("/search?q=quarz&tag=a&tag=b",
HTTP::Headers.of({"Host" => "example.com"}))
req.path # => "/search"
req.query # => "q=quarz&tag=a&tag=b"
req.query_params["tag"]
# => ["a", "b"]
req.host # => "example.com"
Class methods
def self.build(method: String, target: String, headers: HTTP::Headers = …, body: String = …, remote_address: Socket::Address? = …) -> HTTP::Server::Request
A request for a test: HTTP::Server::Request.get("/users/1").
def self.get(target: String, headers: HTTP::Headers = …) -> HTTP::Server::Request
A GET request for a test, with no body.
def self.head(target: String, headers: HTTP::Headers = …) -> HTTP::Server::Request
A HEAD request for a test.
def self.delete(target: String, headers: HTTP::Headers = …) -> HTTP::Server::Request
A DELETE request for a test.
def self.post(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Server::Request
A POST request for a test, its body body.
req = HTTP::Server::Request.post("/users", "name=quarz",
HTTP::Headers.of({"Content-Type" => "application/x-www-form-urlencoded"}))
req.form_params # => {"name" => ["quarz"]}
def self.put(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Server::Request
A PUT request for a test, its body body.
def self.patch(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Server::Request
A PATCH request for a test, its body body.
Methods
def method -> String
The method as sent: "GET", or any token the client sent.
def target -> String
The request target as sent: "/users/1?x=1".
def path -> String
The target's path, percent-decoded: "/users/1".
def query -> String
The target's query, as sent: "x=1" ("" when there is none).
def version -> String
"HTTP/1.1" or "HTTP/1.0".
def headers -> HTTP::Headers
The request's header fields.
def body -> HTTP::Body
The body, read from the connection as the handler asks for it.
def remote_address -> Socket::Address?
The peer's address; nil on a UNIX socket and in a built request.
def params -> Hash[String, String]
The path parameters the router bound ({id} in /users/{id});
empty otherwise.
def proxies -> HTTP::Proxies
The proxies whose X-Forwarded-* headers are believed, and whether the peer is one.
def trusted -> Bool
Whether the peer is a trusted proxy (always, on a UNIX socket).
def tls -> Bool
Whether the connection is TLS (the server's tls:).
def to_h -> Hash[Symbol, Object]
The fields as a Hash, by name.
def with(*, method: String = …, target: String = …, path: String = …, query: String = …, version: String = …, headers: HTTP::Headers = …, body: HTTP::Body = …, remote_address: Socket::Address? = …, params: Hash[String, String] = …, proxies: HTTP::Proxies = …, trusted: Bool = …, tls: Bool = …) -> HTTP::Server::Request
A copy with the fields given replaced.
def host -> String?
The Host header, as received.
def content_length -> Int?
The body's Content-Length; nil for a chunked body.
def query_params -> Hash[String, Array[String]]
The query's parameters, decoded (+ as a space), each name with its
values in order.
def form_params -> Hash[String, Array[String]]
The parameters of an application/x-www-form-urlencoded body, as
#query_params decodes them; empty for another content type. Reads the
body (Body#read), so it raises what that raises.
def scheme -> String
"https" on a TLS connection (the server's tls:), "http"
otherwise; from a trusted proxy, what its X-Forwarded-Proto says
(what the client used to reach the proxy).
def remote_ip -> String?
The client's address: the peer's, or, from a trusted proxy, the last address of X-Forwarded-For that is not a trusted proxy's.
def keep_alive? -> Bool
Whether the client wants the connection kept: HTTP/1.1 unless it sent
Connection: close, HTTP/1.0 only with Connection: keep-alive.