http.bend fails
raw source on the hub · import 0x9c7a61e05d37da832cbd93dd7ae504d9/http.bend as Http
1 import
import Base
Types
type Req source · line 9 · raw
Data
Req@method:String -> @path:String -> @headers:Map<&2, String> -> @body:String -> Req
type Res source · line 12 · raw
Data
Res@status:U32 -> @headers:Map<&2, String> -> @body:String -> Res
type Fields source · line 15 · raw
Data
FieldsBadFields
FieldsOk@m:Map<&2, String> -> Fields
type HexSize source · line 211 · raw
Data
HexSize@n:U32 -> @rest:String -> HexSize
type Step source · line 214 · raw
Data
StepFailStep
StepDone@body:String -> Step
StepNext@rest:String -> @acc:String -> Step
type Frame source · line 459 · raw
Data
Bad: never a message. More: a valid prefix; read on. Done: a whole response.
FrameBadFrame
FrameMoreFrame
FrameDone@res:Res -> Frame
Definitions
def empty source · line 19 · raw
Map<&2, String>
def sanitize.cons source · line 22 · raw
@ch:Char -> @rest:String -> @drop:Bool -> String
def sanitize source · line 29 · raw
@s:String -> String
def drop_cr.if source · line 36 · raw
@+s:String -> @cr:Bool -> String
def drop_cr source · line 43 · raw
@+s:String -> String
def take_sp.go source · line 46 · raw
@s:String -> @+acc:String -> Pair(String, String)
def take_sp source · line 53 · raw
@s:String -> Pair(String, String)
def start_line.ver source · line 56 · raw
@m:String -> @pv:Pair(String, String) -> Pair(String, Pair(String, String))
def start_line.rest source · line 60 · raw
@mr:Pair(String, String) -> Pair(String, Pair(String, String))
def start_line source · line 64 · raw
@s:String -> Pair(String, Pair(String, String))
def split_at_blank.go source · line 67 · raw
@s:String -> @e:Bool -> @w:U32 -> @acc:String -> Pair(String, String)
def split_at_blank source · line 79 · raw
@s:String -> Pair(String, String)
def split_colon.go source · line 82 · raw
@s:String -> @+acc:String -> Pair(String, String)
def split_colon source · line 89 · raw
@s:String -> Pair(String, String)
def has_header.of source · line 92 · raw
@r:Pair(Map<&2, String>, Bool) -> Bool
def has_header source · line 96 · raw
@+h:Map<&2, String> -> @k:String -> Bool
def header.of source · line 99 · raw
@r:Pair(Map<&2, String>, String) -> String
def header source · line 103 · raw
@+h:Map<&2, String> -> @k:String -> String
def folded source · line 106 · raw
@+line:String -> Bool
def tracked source · line 109 · raw
@+k:String -> Bool
def fields_put.dup source · line 112 · raw
@m:Map<&2, String> -> @k:String -> @v:String -> @bad:Bool -> Fields
def fields_put.key source · line 119 · raw
@+m:Map<&2, String> -> @+k:String -> @v:String -> Fields
def fields_put.kv source · line 122 · raw
@m:Map<&2, String> -> @kv:Pair(String, String) -> Fields
def fields_put.fold source · line 126 · raw
@m:Map<&2, String> -> @line:String -> @fold:Bool -> Fields
def fields_put.empty source · line 133 · raw
@m:Map<&2, String> -> @+line:String -> @e:Bool -> Fields
def fields_put.ok source · line 140 · raw
@m:Map<&2, String> -> @+line:String -> Fields
def fields_put source · line 143 · raw
@acc:Fields -> @line:String -> Fields
def parse.headers.done source · line 150 · raw
@acc:Fields -> Maybe<&2, Map<&2, String>>
def parse.headers source · line 157 · raw
@xs:List<&2, String> -> @acc:Fields -> Maybe<&2, Map<&2, String>>
def parse_u32.digit source · line 164 · raw
@+c:U32 -> Bool
def parse_u32.add source · line 167 · raw
@acc:U32 -> @c:U32 -> U32
def parse_u32.done source · line 170 · raw
@acc:U32 -> @bad:Bool -> Maybe<&2, U32>
def parse_u32.go source · line 177 · raw
@s:String -> @acc:U32 -> @bad:Bool -> Maybe<&2, U32>
def parse_u32 source · line 184 · raw
@s:String -> Maybe<&2, U32>
def parse.take.if source · line 193 · raw
@+rest:String -> @+k:Nat -> @short:Bool -> Maybe<&2, String>
def parse.take.have source · line 201 · raw
@+rest:String -> @+k:Nat -> Maybe<&2, String>
RFC 9112 §8: fewer bytes than Content-Length is an incomplete message.
def parse.take source · line 204 · raw
@rest:String -> @n:Maybe<&2, U32> -> Maybe<&2, String>
def is_hex source · line 219 · raw
@+c:U32 -> Bool
def hexv source · line 222 · raw
@+c:U32 -> U32
def chunk.lf1 source · line 225 · raw
@r:String -> @n:U32 -> @lf:Bool -> Maybe<&2, HexSize>
def chunk.lf source · line 232 · raw
@t:String -> @n:U32 -> Maybe<&2, HexSize>
def chunk.ext source · line 240 · raw
@s:String -> @+n:U32 -> Maybe<&2, HexSize>
RFC 9112 §7.1.1: recipients ignore unknown chunk extensions.
def chunk.size.end source · line 247 · raw
@+c:U32 -> @+t:String -> @+n:U32 -> @seen:Bool -> Maybe<&2, HexSize>
def chunk.size.go source · line 254 · raw
@s:String -> @+acc:U32 -> @+seen:Bool -> Maybe<&2, HexSize>
def chunk.size source · line 261 · raw
@s:String -> Maybe<&2, HexSize>
def chunk.trailer.ok source · line 264 · raw
@acc:String -> @ok:Bool -> Step
def chunk.trailer.end source · line 271 · raw
@hb:Pair(String, String) -> @acc:String -> Step
def chunk.trailer.if source · line 275 · raw
@rest:String -> @acc:String -> @blank:Bool -> Step
def chunk.trailer source · line 283 · raw
@+rest:String -> @acc:String -> Step
ponytail: trailer fields are dropped unparsed (§7.1.2 allows discarding)
def chunk.crlf.if source · line 286 · raw
@data:String -> @+after:String -> @acc:String -> @ok:Bool -> Step
def chunk.crlf source · line 293 · raw
@data:String -> @+after:String -> @acc:String -> Step
def chunk.data.if source · line 296 · raw
@+rest:String -> @+k:Nat -> @acc:String -> @short:Bool -> Step
def chunk.data source · line 303 · raw
@+rest:String -> @+k:Nat -> @acc:String -> Step
def chunk.step.n source · line 306 · raw
@+n:U32 -> @rest:String -> @acc:String -> @zero:Bool -> Step
def chunk.step.got source · line 313 · raw
@got:Maybe<&2, HexSize> -> @acc:String -> Step
def chunk.step source · line 320 · raw
@s:String -> @acc:String -> Step
def chunk.go source · line 324 · raw
@fuel:Nat -> @st:Step -> Maybe<&2, String>
ponytail: acc ++ per chunk is O(body * chunks); a chunk list if bodies get big
def chunk.decode source · line 338 · raw
@+s:String -> Maybe<&2, String>
Every chunk eats at least 3 bytes, so length(s) steps always suffice.
def parse.body.cl source · line 341 · raw
@+h:Map<&2, String> -> @rest:String -> @hascl:Bool -> Maybe<&2, String>
def parse.body.chunked.eq source · line 348 · raw
@rest:String -> @ok:Bool -> Maybe<&2, String>
def parse.body.chunked.val source · line 355 · raw
@te:String -> @rest:String -> Maybe<&2, String>
def parse.body.chunked source · line 358 · raw
@+h:Map<&2, String> -> @rest:String -> @hascl:Bool -> Maybe<&2, String>
def parse.body.te source · line 365 · raw
@+h:Map<&2, String> -> @rest:String -> @te:Bool -> Maybe<&2, String>
def parse.body source · line 372 · raw
@+h:Map<&2, String> -> @rest:String -> Maybe<&2, String>
def parse.finish source · line 375 · raw
@method:String -> @path:String -> @h:Map<&2, String> -> @body:Maybe<&2, String> -> Maybe<&2, Req>
def parse.host source · line 382 · raw
@method:String -> @path:String -> @+h:Map<&2, String> -> @rest:String -> @has:Bool -> Maybe<&2, Req>
def parse.fields source · line 389 · raw
@method:String -> @path:String -> @rest:String -> @fs:Maybe<&2, Map<&2, String>> -> Maybe<&2, Req>
def target_ok source · line 396 · raw
@+p:String -> Bool
def parse.target source · line 399 · raw
@method:String -> @+path:String -> @headers:List<&2, String> -> @rest:String -> @ok:Bool -> Maybe<&2, Req>
def parse.ver source · line 406 · raw
@method:String -> @+path:String -> @v:String -> @headers:List<&2, String> -> @rest:String -> @ok:Bool -> Maybe<&2, Req>
def parse.empty_method source · line 413 · raw
@method:String -> @path:String -> @+v:String -> @headers:List<&2, String> -> @rest:String -> @empty:Bool -> Maybe<&2, Req>
def parse.start3 source · line 420 · raw
@mpv:Pair(String, Pair(String, String)) -> @headers:List<&2, String> -> @rest:String -> Maybe<&2, Req>
def parse.lines source · line 424 · raw
@xs:List<&2, String> -> @rest:String -> Maybe<&2, Req>
def parse.head source · line 431 · raw
@head:String -> @rest:String -> Maybe<&2, Req>
def parse.of source · line 434 · raw
@hb:Pair(String, String) -> Maybe<&2, Req>
def parse source · line 438 · raw
@raw:String -> Maybe<&2, Req>
def parse.res.cl source · line 441 · raw
@+h:Map<&2, String> -> @rest:String -> @hascl:Bool -> Maybe<&2, String>
def parse.res.te source · line 448 · raw
@+h:Map<&2, String> -> @rest:String -> @te:Bool -> Maybe<&2, String>
def parse.res.body source · line 455 · raw
@+h:Map<&2, String> -> @rest:String -> Maybe<&2, String>
def frame.cut source · line 465 · raw
@closed:Bool -> Frame
RFC 9112 §8: a message cut short by close is incomplete, not valid.
def frame.wait source · line 472 · raw
@res:Res -> @wait:Bool -> Frame
def frame.done source · line 479 · raw
@status:U32 -> @h:Map<&2, String> -> @body:Maybe<&2, String> -> @+closed:Bool -> @open:Bool -> Frame
def frame.open source · line 487 · raw
@+h:Map<&2, String> -> Bool
RFC 9112 §6.3 (8): no TE and no CL ⇒ the body runs until the server closes.
def frame.nobody source · line 492 · raw
@+status:U32 -> @head:Bool -> Bool
RFC 9112 §6.3 (1): HEAD, 1xx, 204 and 304 responses end at the blank line. ponytail: 1xx is returned as final; skip interim responses if a server sends 103
def frame.status source · line 495 · raw
@status:U32 -> @+h:Map<&2, String> -> @rest:String -> @closed:Bool -> @nobody:Bool -> Frame
def parse.res.fields source · line 502 · raw
@+status:U32 -> @rest:String -> @fs:Maybe<&2, Map<&2, String>> -> @closed:Bool -> @head:Bool -> Frame
def parse.res.num source · line 509 · raw
@code:Maybe<&2, U32> -> @headers:List<&2, String> -> @rest:String -> @closed:Bool -> @head:Bool -> Frame
def parse.res.ver source · line 516 · raw
@code:String -> @headers:List<&2, String> -> @rest:String -> @closed:Bool -> @head:Bool -> @ok:Bool -> Frame
def parse.res.start3 source · line 523 · raw
@mpv:Pair(String, Pair(String, String)) -> @headers:List<&2, String> -> @rest:String -> @closed:Bool -> @head:Bool -> Frame
def parse.res.lines source · line 527 · raw
@xs:List<&2, String> -> @rest:String -> @closed:Bool -> @head:Bool -> Frame
def parse.res.blank source · line 534 · raw
@hd:String -> @rest:String -> @+closed:Bool -> @head:Bool -> @ok:Bool -> Frame
def parse.res.of source · line 541 · raw
@hb:Pair(String, String) -> @closed:Bool -> @head:Bool -> Frame
def frame source · line 546 · raw
@raw:String -> @closed:Bool -> @head:Bool -> Frame
frame(bytes so far, server closed?, request was HEAD?)
def frame.res source · line 549 · raw
@f:Frame -> Maybe<&2, Res>
def parse_res source · line 558 · raw
@raw:String -> Maybe<&2, Res>
def res_body.res source · line 561 · raw
@res:Res -> String
def res_body source · line 565 · raw
@m:Maybe<&2, Res> -> String
def got_body.req source · line 572 · raw
@req:Req -> String
def got_body source · line 576 · raw
@m:Maybe<&2, Req> -> String
def body.of source · line 583 · raw
@hb:Pair(String, String) -> String
def body source · line 587 · raw
@s:String -> String
def headers_block.go source · line 590 · raw
@xs:List<&2, Sigma<&2, &2, String, _ => String>> -> @acc:String -> String
def headers_block source · line 597 · raw
@h:Map<&2, String> -> String
def response source · line 600 · raw
@status:U32 -> @headers:Map<&2, String> -> @body:String -> String
def nat_u32 source · line 603 · raw
@n:Nat -> U32
def encode source · line 610 · raw
@r:Res -> String
def request source · line 614 · raw
@method:String -> @path:String -> @headers:Map<&2, String> -> @body:String -> String
def encode_req source · line 617 · raw
@method:String -> @path:String -> @host:String -> @+body:String -> String
def fetch.close source · line 620 · raw
@s:Socket -> @r:Maybe<&2, Res> -> IO(Maybe<&2, Res>)
def fetch.cap source · line 625 · raw
@f:Frame -> @over:Bool -> Frame
def fetch.max source · line 633 · raw
Nat
Untrusted servers must not grow the buffer without bound.
def fetch.next.buf source · line 636 · raw
@s:Socket -> @+buf:String -> @closed:Bool -> @head:Bool -> Pair(Socket, Pair(String, Frame))
def fetch.next.r source · line 639 · raw
@head:Bool -> @s:Socket -> @buf:String -> @r:Result<&1, &1, Pair(U32, String), String> -> Pair(Socket, Pair(String, Frame))
def fetch.next source · line 646 · raw
@head:Bool -> @buf:String -> @m:Pair(Socket, Result<&1, &1, Pair(U32, String), String>) -> Pair(Socket, Pair(String, Frame))
def fetch_sent source · line 664 · raw
@head:Bool -> @m:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Maybe<&2, Res>)
def fetch source · line 670 · raw
@+method:String -> @ip:String -> @port:U32 -> @host:String -> @path:String -> @body:String -> IO(Maybe<&2, Res>)
def get_body.res source · line 676 · raw
@res:Res -> String
def get_body source · line 680 · raw
@m:Maybe<&2, Res> -> String
def get source · line 687 · raw
@ip:String -> @port:U32 -> @host:String -> @path:String -> IO(String)
def sent_fin source · line 692 · raw
@m:Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Unit)
def reply_send source · line 696 · raw
@s:Socket -> @res:Res -> IO(Unit)
Templates
template reply_handle source · line 701 · raw
@-h:(@_:Req -> IO(Res)) -> @s:Socket -> @req:Req -> IO(Unit)
template reply_parsed source · line 706 · raw
@-h:(@_:Req -> IO(Res)) -> @s:Socket -> @m:Maybe<&2, Req> -> IO(Unit)
template reply_ok source · line 713 · raw
@-h:(@_:Req -> IO(Res)) -> @s:Socket -> @raw:String -> IO(Unit)
template reply source · line 716 · raw
@-h:(@_:Req -> IO(Res)) -> @m:Pair(Socket, Result<&1, &1, Pair(U32, String), String>) -> IO(Unit)
template talk source · line 724 · raw
@-h:(@_:Req -> IO(Res)) -> @s:Socket -> IO(Unit)
template conn source · line 729 · raw
@-h:(@_:Req -> IO(Res)) -> @m:Pair(Listener, Result<&1, &1, Pair(U32, String), Socket>) -> IO(Listener)
template serve source · line 743 · raw
@-h:(@_:Req -> IO(Res)) -> @+port:U32 -> IO(Unit)
Unsafe
unsafe fetch.read source · line 652 · raw
@+head:Bool -> @st:Pair(Socket, Pair(String, Frame)) -> IO(Maybe<&2, Res>)
Reads until frame says Done or Bad; an empty recv means the server closed.
unsafe loop source · line 737 · raw
@-h:(@_:Req -> IO(Res)) -> @l:Listener -> IO(Unit)