Skip to content

Std.Http.Request

enum Method

The request methods. A method not in this list cannot be sent, and an HTTP service answers it with 405.

  • Get
  • Head
  • Post
  • Put
  • Patch
  • Delete
  • Options
type Request(method: Method, url: String, headers: List[(String, String)], body: String)

A request. headers are sent in the written order. The body is text, sent as UTF-8.

  • method: Method
  • url: String
  • headers: List[(String, String)]
  • body: String
fn new(method: Method, url: String) -> Request

A request with no headers and an empty body.

fn add_header(req: Request, name: String, value: String) -> Request

Adds a header after the ones already in req.

fn header(req: Request, name: String) -> Option[String]

The first value of the header name, compared without case.

fn header_values(req: Request, name: String) -> List[String]

All values of the header name in order, compared without case. Not named headers, the field (E3109).

fn path(req: Request) -> String

The path of url without the query, as written: "/api/a%20b" for "https://example.com/api/a%20b?x=1". "/" if the path is empty.

fn segments(req: Request) -> List[String]

The non-empty segments of the path, each percent-decoded: ["api", "a b"] for "/api/a%20b". A segment that does not decode is kept as written.

fn query(req: Request) -> List[(String, String)]

The pairs of the query of url, read as decode_query reads them. Empty without a ?. A pair that does not decode is kept as written.

fn encode_query(pairs: List[(String, String)]) -> String

The query string of pairs, each part percent-encoded (q=%E6%9D%B1&page=2). Every byte of the UTF-8 of a name or a value is written as % and two upper-case hexadecimal digits, except ASCII letters, digits and -_.!~*'().

fn decode_query(s: String) -> List[(String, String)] fails ParseError

The pairs of the query string s, the inverse of encode_query: split at &, then at the first = of each pair (a pair without = has an empty value), + read as a space, then percent-decoded. Fails with ParseError if a % is not followed by two hexadecimal digits or the decoded bytes are not UTF-8. "" has no pairs.