~/bend-docscommunity

http.bend checks

raw source on the hub · import gralha-http-core@0.1.0.0/http.bend as Http

HTTP/1.1 messages: requests parsed from text, responses serialized to it. Pure: no IO, no foreign code. A server reads the text from a socket (gralha-http-server); a header name compares without case.

1 import
import Base

Laws

law ok_is_200 provedsource · line 393 · raw

@t:String -> @b:String -> {response.status(ok(t, b)) == 200 : U32}

law with_keeps_status provedsource · line 401 · raw

@r:Response -> @n:String -> @v:String -> {response.status(response.with(r, n, v)) == response.status(r) : U32}

Types

type Request source · line 229 · raw

Data

type Response source · line 309 · raw

Data

Definitions

def when source · line 10 · raw

@-A:Type -> @c:Bool -> @yes:(@_:Unit -> A) -> @no:(@_:Unit -> A) -> A

One of two computations, run on c; only the chosen one runs.

def cut.go source · line 18 · raw

@s:String -> @+sep:String -> @+acc:String -> Maybe<&1, Pair(String, String)>

The text before the first sep and the text after it, or None without sep.

def cut source · line 27 · raw

@s:String -> @+sep:String -> Maybe<&1, Pair(String, String)>

def before.cut source · line 30 · raw

@c:Maybe<&1, Pair(String, String)> -> @whole:String -> String

def before source · line 38 · raw

@+s:String -> @+sep:String -> String

The text before sep, or all of it without sep.

def after.cut source · line 41 · raw

@c:Maybe<&1, Pair(String, String)> -> String

def after source · line 49 · raw

@s:String -> @+sep:String -> String

The text after sep, or "" without sep.

def utf8.width source · line 55 · raw

@+c:U32 -> U32

def utf8.count source · line 59 · raw

@s:String -> @acc:U32 -> U32

def utf8.length source · line 67 · raw

@s:String -> U32

The bytes a text takes in UTF-8, as Content-Length counts them.

def utf8.push source · line 71 · raw

@+c:U32 -> @+acc:List<&2, U32> -> List<&2, U32>

A character's UTF-8 bytes, prepended to acc in reverse.

def utf8.need source · line 83 · raw

@+b:U32 -> @+need:U32 -> U32

Decoding reads a byte at a time: need is the continuation bytes still owed and code the bits so far. A byte out of place is U+FFFD.

def utf8.code source · line 89 · raw

@+b:U32 -> @+need:U32 -> @+code:U32 -> U32

def utf8.emit source · line 95 · raw

@+b:U32 -> @+need:U32 -> @+code:U32 -> @+acc:String -> String

def utf8.decode.go source · line 103 · raw

@bytes:List<&2, U32> -> @+need:U32 -> @+code:U32 -> @acc:String -> String

def utf8.decode source · line 110 · raw

@bytes:List<&2, U32> -> String

def hex.digit source · line 116 · raw

@+c:U32 -> U32

def hex.is_digit source · line 120 · raw

@+c:U32 -> Bool

def url.bytes source · line 124 · raw

@s:String -> @+acc:List<&2, U32> -> List<&2, U32>

def url.decode source · line 138 · raw

@s:String -> String

A url component with %XX escapes and + (a space, as forms send it) decoded; the bytes read as UTF-8.

def target.path source · line 142 · raw

@+target:String -> String

A target's path: the part before ?.

def target.query source · line 146 · raw

@target:String -> String

A target's query: the part after ?, or "".

def query.find source · line 149 · raw

@pairs:List<&2, String> -> @+name:String -> Maybe<&2, String>

def query.get source · line 158 · raw

@query:String -> @+name:String -> Maybe<&2, String>

The first value of a query parameter, decoded, e.g. query.get("a=1&b=x%20y", "b").

def header.find source · line 168 · raw

@headers:List<&2, Header> -> @+name:String -> Maybe<&2, String>

The value of the first header named name, any case.

def header.get source · line 176 · raw

@headers:List<&2, Header> -> @name:String -> Maybe<&2, String>

def header.has source · line 179 · raw

@headers:List<&2, Header> -> @name:String -> Bool

def header.line source · line 182 · raw

@c:Maybe<&1, Pair(String, String)> -> @rest:List<&2, Header> -> List<&2, Header>

def header.parse source · line 190 · raw

@lines:List<&2, String> -> List<&2, Header>

Header lines, "Name: value" each; a line with no colon is skipped.

def header.text source · line 197 · raw

@headers:List<&2, Header> -> String

def digits source · line 204 · raw

@s:String -> Bool

def number source · line 212 · raw

@+s:String -> Maybe<&2, U32>

A decimal number made of digits only, as Content-Length is.

def number.or_zero source · line 215 · raw

@m:Maybe<&2, String> -> U32

def content.length source · line 223 · raw

@headers:List<&2, Header> -> U32

The Content-Length a header list declares, or 0.

def request.line source · line 232 · raw

@parts:List<&2, String> -> @headers:List<&2, Header> -> @body:String -> Maybe<&2, Request>

def request.head source · line 239 · raw

@lines:List<&2, String> -> @body:String -> Maybe<&2, Request>

def request.cut source · line 246 · raw

@c:Maybe<&1, Pair(String, String)> -> Maybe<&2, Request>

def request.parse source · line 255 · raw

@text:String -> Maybe<&2, Request>

A request: "METHOD target HTTP/x.y", header lines, a blank line, the body (all that follows it). None when the head is unfinished or malformed.

def request.complete.cut source · line 258 · raw

@c:Maybe<&1, Pair(String, String)> -> Bool

def request.complete source · line 267 · raw

@text:String -> Bool

Whether text holds a whole request: its head ended, and as many body bytes as its Content-Length (none without one).

def request.method source · line 270 · raw

@r:Request -> String

def request.target source · line 275 · raw

@r:Request -> String

def request.path source · line 280 · raw

@r:Request -> String

def request.body source · line 285 · raw

@r:Request -> String

def request.header source · line 291 · raw

@r:Request -> @name:String -> Maybe<&2, String>

A header of the request, any case.

def request.query source · line 297 · raw

@r:Request -> @+name:String -> Maybe<&2, String>

A query parameter of the request's target, decoded.

def request.is source · line 303 · raw

@+r:Request -> @method:String -> @path:String -> Bool

Whether the request is method on path, e.g. request.is(r, "GET", "/").

def reason source · line 313 · raw

@+code:U32 -> String

The reason phrase of a status code, or "" for one not listed.

def response source · line 352 · raw

@+status:U32 -> @content_type:String -> @body:String -> Response

A response with a status, a Content-Type and a body.

def ok source · line 356 · raw

@content_type:String -> @body:String -> Response

A 200 response with a Content-Type and a body.

def status source · line 360 · raw

@+code:U32 -> Response

A plain-text response with the status's reason phrase as its body.

def response.with source · line 364 · raw

@r:Response -> @name:String -> @value:String -> Response

The response with one more header, after the ones it has.

def response.status source · line 369 · raw

@r:Response -> U32

def length.with source · line 379 · raw

@+headers:List<&2, Header> -> @+body:String -> List<&2, Header>

def response.text source · line 385 · raw

@r:Response -> String

The response as sent: its head, with a Content-Length counted in UTF-8 bytes after its own headers (unless it has one), then its body.