OxL Reference

data Request

A request received by a Server.

Example:

oxl✓ checked in CI
use std.http { Request, Header }

fn sample() -> Request {
  Request{
    method: "GET", target: "/search?q=oxl&tag=a&tag=b", path: "/search", rawQuery: "q=oxl&tag=a&tag=b", version: "HTTP/1.1",
    headers: [Header{ name: "Accept", value: "text/html" }, Header{ name: "Cookie", value: "sid=42; theme=dark" }, Header{ name: "X-Id", value: "1" }, Header{ name: "x-id", value: "2" }],
    body: Utf8.encode("payload"), peer: "127.0.0.1:50000", params: [Header{ name: "id", value: "7" }]
  }
}

fn main() io {
  let r = sample()
  print("{r.method} {r.path} q={r.query("q") ?? "-"} id={r.param("id") ?? "-"}")
}
Output
GET /search q=oxl id=7
pub(api) data Request

Thread safety. a plain value owned by the handler task.

Since. 1.0.0-beta

Fields

pub(api) method: str

GET, POST, ...

pub(api) target: str

The request target as sent (/a/b?x=1).

pub(api) path: str

The path part of the target, still percent-encoded.

pub(api) rawQuery: str

The part after ?, still percent-encoded.

pub(api) version: str

HTTP/1.1 or HTTP/1.0.

pub(api) headers: List<Header>

Header fields in the order received.

pub(api) body: bytes

The complete body (de-chunked).

pub(api) peer: str

ip:port of the client.

pub(api) params: List<Header>

Route parameters (:name, *rest), percent-decoded; filled by the Router.

pub(api) streamed: bool = false

The body was not read before the handler started (ServerConfig.streamBodyAbove): body is empty, read it with stream().

Methods

stream() -> BodyReader
Reader for the body
header(name: str) -> str?
The first header with this name (case-insensitive).
headerAll(name: str) -> List<str>
All values of the header with this name (case-insensitive), in order.
query(name: str) -> str?
The first value of the query parameter name (decoded).
queryAll(name: str) -> List<str>
All values of the query parameter name (decoded), in order.
param(name: str) -> str?
A route parameter.
cookie(name: str) -> str?
The value of the cookie name from the Cookie header.
text() -> str | DecodeError
The body as UTF-8 text.
bodyLen() -> usize
The size of the buffered body in bytes (0 for a streamed request).

Defined in: std/http/http.oxl:1164

See also