air/http.bend checks
raw source on the hub · import 0x1efee7e6292e6267db2ca5c7e267456a/air/http.bend as Http
2 imports
import Base import ./text.bend as Text
Types
type Limits source · line 17 · raw
Data
Byte caps on a request: the head (request line plus headers), the number of header lines, the URL, and the body. Past them the server answers 431, 431, 414 or 413 and closes the connection.
Limits@head:U32 -> @headers:U32 -> @url:U32 -> @body:U32 -> Limits
type Method source · line 46 · raw
Data
GETMethod
POSTMethod
PUTMethod
DELETEMethod
PATCHMethod
HEADMethod
OPTIONSMethod
Other@name:String -> Method
type Request source · line 100 · raw
Data
Request@method:Method -> @version:String -> @target:String -> @path:String -> @query:Map<&2, String> -> @headers:Map<&2, String> -> @params:Map<&2, String> -> @body:String -> Request
type Parsed source · line 367 · raw
Data
A parsed head, or the status that refuses it.
Parsed@req:Request -> Parsed
Refused@status:U32 -> Parsed
type Framing source · line 438 · raw
Data
How the body is delimited, decided from the head alone.
NoBodyFraming
Fixed@size:U32 -> Framing
ChunkedFraming
Unframed@status:U32 -> Framing
type Response source · line 524 · raw
Data
Response@status:U32 -> @headers:Map<&2, String> -> @body:String -> Response
Definitions
def Limits.default source · line 20 · raw
Limits
def Limits.head source · line 23 · raw
@l:Limits -> U32
def Limits.headers source · line 28 · raw
@l:Limits -> U32
def Limits.url source · line 33 · raw
@l:Limits -> U32
def Limits.body source · line 38 · raw
@l:Limits -> U32
def Method.parse source · line 56 · raw
@+s:String -> Method
def Method.show source · line 75 · raw
@m:Method -> String
def Method.is_eq source · line 94 · raw
@a:Method -> @b:Method -> Bool
def Request.method source · line 112 · raw
@r:Request -> Method
def Request.version source · line 118 · raw
@r:Request -> String
"HTTP/1.1" or "HTTP/1.0", as the request line said.
def Request.target source · line 124 · raw
@r:Request -> String
The request-target as received: raw path and query, undecoded.
def Request.path source · line 131 · raw
@r:Request -> String
The path in its normal form: percent-decoded, . and .. resolved,
repeated slashes collapsed, a trailing slash kept. * for OPTIONS *.
def Request.body source · line 136 · raw
@r:Request -> String
def Request.header source · line 143 · raw
@r:Request -> @name:String -> String
A header by name, case-insensitive; "" when absent. A repeated header reads as its values joined with ", ".
def Request.query source · line 149 · raw
@r:Request -> @key:String -> String
A query-string value; "" when absent.
def Request.param source · line 155 · raw
@r:Request -> @key:String -> String
A path parameter bound by the route, like :id; "" when absent.
def Request.with_params source · line 160 · raw
@r:Request -> @params:Map<&2, String> -> Request
def Request.with_body source · line 165 · raw
@r:Request -> @body:String -> Request
def Request.joined source · line 170 · raw
@old:String -> @v:String -> String
def Request.merge_header source · line 177 · raw
@r:Pair(Map<&2, String>, String) -> @key:String -> @v:String -> Map<&2, String>
def Request.add_header source · line 181 · raw
@m:Map<&2, String> -> @+key:String -> @v:String -> Maybe<&2, Map<&2, String>>
def Request.header_line.fin source · line 190 · raw
@m:Map<&2, String> -> @blank:Bool -> @folded:Bool -> @split:Maybe<&2, 0x1efee7e6292e6267db2ca5c7e267456a/air/text.Two> -> Maybe<&2, Map<&2, String>>
A header line is name: value. Blank lines are skipped; a line that
starts with whitespace (obsolete folding) or has no colon is refused.
def Request.header_line source · line 202 · raw
@m:Map<&2, String> -> @+line:String -> Maybe<&2, Map<&2, String>>
def Request.parse_headers source · line 209 · raw
@lines:List<&2, String> -> @m:Maybe<&2, Map<&2, String>> -> Maybe<&2, Map<&2, String>>
def Request.set_decoded source · line 218 · raw
@m:Map<&2, String> -> @k:Maybe<&2, String> -> @v:Maybe<&2, String> -> Maybe<&2, Map<&2, String>>
def Request.add_query source · line 227 · raw
@m:Map<&2, String> -> @skip:Bool -> @kv:0x1efee7e6292e6267db2ca5c7e267456a/air/text.Two -> Maybe<&2, Map<&2, String>>
A query pair is key=value, both percent-decoded with '+' as space;
a bad escape in either refuses the request.
def Request.parse_query source · line 235 · raw
@parts:List<&2, String> -> @m:Maybe<&2, Map<&2, String>> -> Maybe<&2, Map<&2, String>>
def Request.after_authority source · line 254 · raw
@rest:String -> String
def Request.strip_origin.pick source · line 257 · raw
@+target:String -> @http:Bool -> @https:Bool -> String
def Request.strip_origin source · line 268 · raw
@+target:String -> String
"http://host/x" and "https://host/x" become "/x"; anything else is returned as is.
def Request.push_decoded source · line 273 · raw
@acc:List<&2, String> -> @d:Maybe<&2, String> -> Maybe<&2, List<&2, String>>
def Request.decode_segments source · line 280 · raw
@segs:List<&2, String> -> @acc:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
def Request.pop_segment source · line 289 · raw
@acc:List<&2, String> -> Maybe<&2, List<&2, String>>
def Request.step_dot source · line 298 · raw
@acc:List<&2, String> -> @+seg:String -> Maybe<&2, List<&2, String>>
. is dropped, .. pops the segment before it, and .. at the root
is refused.
def Request.resolve_dots.go source · line 307 · raw
@segs:List<&2, String> -> @acc:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
def Request.resolve_dots source · line 316 · raw
@segs:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
def Request.render_path.go source · line 325 · raw
@segs:List<&2, String> -> @rev:String -> String
Builds the path reversed, so each segment is prepended in constant
time; render_path.fin turns it around.
def Request.render_path.fin source · line 332 · raw
@rev:String -> @trailing:Bool -> String
def Request.render_path source · line 339 · raw
@segs:List<&2, String> -> @trailing:Bool -> String
def Request.normalize.fin source · line 346 · raw
@resolved:Maybe<&2, List<&2, String>> -> @trailing:Bool -> Maybe<&2, String>
def Request.normalize.go source · line 353 · raw
@+path:String -> Maybe<&2, String>
def Request.normalize source · line 359 · raw
@+raw:String -> Maybe<&2, String>
The normal form of a raw path, or None when it must be refused.
def Request.parse.fin source · line 373 · raw
@method:String -> @version:String -> @target:String -> @url_ok:Bool -> @version_ok:Bool -> @count_ok:Bool -> @headers:Maybe<&2, Map<&2, String>> -> @path:Maybe<&2, String> -> @query:Maybe<&2, Map<&2, String>> -> Parsed
The refusals in order: 414 for the URL, 505 for the version, 431 for the header count, 400 for a bad header, path or query.
def Request.parse.url source · line 400 · raw
@method:String -> @version:String -> @target:String -> @url_ok:Bool -> @version_ok:Bool -> @count_ok:Bool -> @headers:Maybe<&2, Map<&2, String>> -> @pq:0x1efee7e6292e6267db2ca5c7e267456a/air/text.Two -> Parsed
Splits the target once into path and query, then normalizes each.
def Request.parse.line source · line 413 · raw
@+limits:Limits -> @parts:List<&2, String> -> @+lines:List<&2, String> -> Parsed
def Request.parse.go source · line 428 · raw
@+limits:Limits -> @lr:0x1efee7e6292e6267db2ca5c7e267456a/air/text.Two -> Parsed
def Request.parse source · line 434 · raw
@+limits:Limits -> @head:String -> Parsed
Parses the request head (everything before the blank line) under the
limits. The body is attached later with Request.with_body.
def Framing.readable source · line 444 · raw
@f:Framing -> @+max:U32 -> Bool
def Request.framing.fixed source · line 455 · raw
@n:Maybe<&2, U32> -> Framing
def Request.framing.pick source · line 464 · raw
@+te:String -> @+cl:String -> Framing
Content-Length and Transfer-Encoding together, a repeated or
non-numeric Content-Length, and any encoding but chunked are refused.
def Request.framing source · line 475 · raw
@+req:Request -> Framing
def Request.keep_alive.pick source · line 478 · raw
@conn:String -> @http10:Bool -> Bool
def Request.keep_alive source · line 487 · raw
@+req:Request -> Bool
HTTP/1.1 keeps the connection unless asked to close; HTTP/1.0 closes unless asked to keep it.
def Request.expects_continue source · line 490 · raw
@+req:Request -> Bool
def Parsed.framing source · line 493 · raw
@p:Parsed -> Framing
def Parsed.keep_alive source · line 500 · raw
@p:Parsed -> Bool
def Parsed.path source · line 507 · raw
@p:Parsed -> String
def Parsed.query source · line 514 · raw
@p:Parsed -> @key:String -> String
def Response.new source · line 527 · raw
@status:U32 -> @body:String -> Response
def Response.status source · line 530 · raw
@r:Response -> U32
def Response.body source · line 535 · raw
@r:Response -> String
def Response.header source · line 540 · raw
@r:Response -> @name:String -> String
def Response.with_status source · line 545 · raw
@r:Response -> @status:U32 -> Response
def Response.with_header source · line 550 · raw
@r:Response -> @name:String -> @value:String -> Response
def Response.empty source · line 555 · raw
@status:U32 -> Response
def Response.text source · line 558 · raw
@body:String -> Response
def Response.html source · line 561 · raw
@body:String -> Response
def Response.json source · line 564 · raw
@body:String -> Response
def Response.redirect source · line 567 · raw
@url:String -> Response
def Response.not_found source · line 570 · raw
Response
def Response.method_not_allowed source · line 574 · raw
@allow:String -> Response
A 405 must say what would have worked: allow is "GET, HEAD, OPTIONS".
def Response.options source · line 578 · raw
@allow:String -> Response
The answer to an OPTIONS request no route claims: 204 with Allow.
def Response.bad_request source · line 581 · raw
Response
def Status.reasons source · line 584 · raw
Map<&2, String>
def Status.reason source · line 615 · raw
@code:U32 -> String
def Response.no_body source · line 619 · raw
@+status:U32 -> Bool
1xx, 204 and 304 responses never carry a body.
def Response.render_header source · line 622 · raw
@kv:0x1efee7e6292e6267db2ca5c7e267456a/air/text.Two -> String
def Response.render_headers source · line 626 · raw
@kvs:List<&2, 0x1efee7e6292e6267db2ca5c7e267456a/air/text.Two> -> @acc:String -> String
def Response.render_body source · line 633 · raw
@body:String -> @omit:Bool -> String
def Response.render_length source · line 642 · raw
@+n:U32 -> @+status:U32 -> String
1xx and 204 have no Content-Length; 304 and HEAD keep the one the full response would have had.
def Response.render source · line 649 · raw
@r:Response -> @head_only:Bool -> @+keep:Bool -> String
The wire form of a response. head_only drops the body, for HEAD
requests. keep picks the Connection header.
def Response.serialize source · line 662 · raw
@r:Response -> String
A full response that closes its connection.