data HTTP::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)
A request, as the server read it or as a test builds it
(HTTP::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::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>:475
Class methods
def self.build(method: String, target: String, headers: HTTP::Headers = …, body: String = …, remote_address: Socket::Address? = …) -> HTTP::Request
A request for a test: HTTP::Request.get("/users/1").
<std:http>:502
def self.get(target: String, headers: HTTP::Headers = …) -> HTTP::Request
A GET request for a test, with no body.
<std:http>:510
def self.head(target: String, headers: HTTP::Headers = …) -> HTTP::Request
A HEAD request for a test.
<std:http>:512
def self.delete(target: String, headers: HTTP::Headers = …) -> HTTP::Request
A DELETE request for a test.
<std:http>:514
def self.post(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Request
A POST request for a test, its body body.
req = HTTP::Request.post("/users", "name=quarz",
HTTP::Headers.of({"Content-Type" => "application/x-www-form-urlencoded"}))
req.form_params # => {"name" => ["quarz"]}
<std:http>:523
def self.put(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Request
A PUT request for a test, its body body.
<std:http>:528
def self.patch(target: String, body: String = …, headers: HTTP::Headers = …) -> HTTP::Request
A PATCH request for a test, its body body.
<std:http>:533
Methods
def method -> String
The method as sent: "GET", or any token the client sent.
<std:http>:477
def target -> String
The request target as sent: "/users/1?x=1".
<std:http>:479
def path -> String
The target's path, percent-decoded: "/users/1".
<std:http>:481
def query -> String
The target's query, as sent: "x=1" ("" when there is none).
<std:http>:483
def version -> String
"HTTP/1.1" or "HTTP/1.0".
<std:http>:485
def headers -> HTTP::Headers
The request's header fields.
<std:http>:487
def body -> HTTP::Body
The body, read from the connection as the handler asks for it.
<std:http>:489
def remote_address -> Socket::Address?
The peer's address; nil on a UNIX socket and in a built request.
<std:http>:491
def params -> Hash[String, String]
The path parameters the router bound ({id} in /users/{id});
empty otherwise.
<std:http>:494
def proxies -> HTTP::Proxies
The proxies whose X-Forwarded-* headers are believed, and whether the peer is one.
<std:http>:497
def trusted -> Bool
Whether the peer is a trusted proxy (always, on a UNIX socket).
<std:http>:499
def to_h -> Hash[Symbol, Object]
The fields as a Hash, by name.
<std:http>:502
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 = …) -> HTTP::Request
A copy with the fields given replaced.
<std:http>:502
def host -> String?
The Host header, as received.
<std:http>:538
def content_length -> Int?
The body's Content-Length; nil for a chunked body.
<std:http>:541
def query_params -> Hash[String, Array[String]]
The query's parameters, decoded (+ as a space), each name with its
values in order.
<std:http>:545
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>:550
def scheme -> String
"http", or "https" when a trusted proxy says so in
X-Forwarded-Proto.
<std:http>:558
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>:571
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>:586