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"

<std:http>:1084

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").

<std:http>:1113

def self.get(target: String, headers: HTTP::Headers = …) -> HTTP::Server::Request

A GET request for a test, with no body.

<std:http>:1121

def self.head(target: String, headers: HTTP::Headers = …) -> HTTP::Server::Request

A HEAD request for a test.

<std:http>:1123

def self.delete(target: String, headers: HTTP::Headers = …) -> HTTP::Server::Request

A DELETE request for a test.

<std:http>:1125

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"]}

<std:http>:1134

def self.put(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Server::Request

A PUT request for a test, its body body.

<std:http>:1139

def self.patch(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Server::Request

A PATCH request for a test, its body body.

<std:http>:1144

Methods

def method -> String

The method as sent: "GET", or any token the client sent.

<std:http>:1086

def target -> String

The request target as sent: "/users/1?x=1".

<std:http>:1088

def path -> String

The target's path, percent-decoded: "/users/1".

<std:http>:1090

def query -> String

The target's query, as sent: "x=1" ("" when there is none).

<std:http>:1092

def version -> String

"HTTP/1.1" or "HTTP/1.0".

<std:http>:1094

def headers -> HTTP::Headers

The request's header fields.

<std:http>:1096

def body -> HTTP::Body

The body, read from the connection as the handler asks for it.

<std:http>:1098

def remote_address -> Socket::Address?

The peer's address; nil on a UNIX socket and in a built request.

<std:http>:1100

def params -> Hash[String, String]

The path parameters the router bound ({id} in /users/{id}); empty otherwise.

<std:http>:1103

def proxies -> HTTP::Proxies

The proxies whose X-Forwarded-* headers are believed, and whether the peer is one.

<std:http>:1106

def trusted -> Bool

Whether the peer is a trusted proxy (always, on a UNIX socket).

<std:http>:1108

def tls -> Bool

Whether the connection is TLS (the server's tls:).

<std:http>:1110

def to_h -> Hash[Symbol, Object]

The fields as a Hash, by name.

<std:http>:1113

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.

<std:http>:1113

def host -> String?

The Host header, as received.

<std:http>:1149

def content_length -> Int?

The body's Content-Length; nil for a chunked body.

<std:http>:1152

def query_params -> Hash[String, Array[String]]

The query's parameters, decoded (+ as a space), each name with its values in order.

<std:http>:1156

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.

<std:http>:1161

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).

<std:http>:1170

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.

<std:http>:1183

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.

<std:http>:1198