~/bend-docscommunity

http/request.bend source

http/request.bend on the hub · documented module

import Baseimport ./text.bend as Timport ./method.bend as Mimport ./headers.bend as Himport ./query.bend as Q# a request as the server hands it over: the method, the target as sent# (origin-form, RFC 9112 §3.2.1: /path?query), the headers, and the body's# bytes, read up to the server's limittype Request is Data:  Request{method: M.Method, target: String, headers: List<&2, H.Header>, body: List<&2, U32>}# Each accessor takes the request whole, as Bend values are used once: to# read several parts, match on Request{m, target, hs, body} insteaddef method(r: Request) -> M.Method:  match r:    case Request{m, _, _, _}:      mdef target(r: Request) -> String:  match r:    case Request{_, t, _, _}:      tdef path.of(c: T.Cut) -> String:  match c:    case T.Cut{p, _}:      p# the target's path, before any ?def path(r: Request) -> String:  match r:    case Request{_, t, _, _}:      path.of(T.cut(t, 63))def query.of(c: T.Cut) -> List<&2, Q.Param>:  match c:    case T.Cut{_, Some{q}}:      Q.parse(q)    case T.Cut{_, None{}}:      []# the target's query pairs, decodeddef query(r: Request) -> List<&2, Q.Param>:  match r:    case Request{_, t, _, _}:      query.of(T.cut(t, 63))def headers(r: Request) -> List<&2, H.Header>:  match r:    case Request{_, _, hs, _}:      hs# the first value of a header, whose name compares ignoring casedef header(r: Request, +name: String) -> Maybe<&2, String>:  match r:    case Request{_, _, hs, _}:      H.get(hs, name)def body(r: Request) -> List<&2, U32>:  match r:    case Request{_, _, _, b}:      b