Std.Http.Request
Method
Section titled “Method”enum MethodThe request methods. A method not in this list cannot be sent, and an HTTP service answers it with 405.
GetHeadPostPutPatchDeleteOptions
Request
Section titled “Request”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: Methodurl: Stringheaders: List[(String, String)]body: String
fn new(method: Method, url: String) -> RequestA request with no headers and an empty body.
add_header
Section titled “add_header”fn add_header(req: Request, name: String, value: String) -> RequestAdds a header after the ones already in req.
header
Section titled “header”fn header(req: Request, name: String) -> Option[String]The first value of the header name, compared without case.
header_values
Section titled “header_values”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) -> StringThe 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.
segments
Section titled “segments”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.
encode_query
Section titled “encode_query”fn encode_query(pairs: List[(String, String)]) -> StringThe 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 -_.!~*'().
decode_query
Section titled “decode_query”fn decode_query(s: String) -> List[(String, String)] fails ParseErrorThe 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.