~/bend-docscommunity

src/packed.bend checks

raw source on the hub · import ezhttp@0.24.0.0/src/packed.bend as Packed

ezhttp/src/packed: a response read off its packed octets (bend-kit-bytes), so its body is never turned into text. Only the heads and the chunk-size lines are read as text, a few octets each; every decision is src/http.bend's, the same one its text parse makes (laws/HeadPlannedBeforeBody.bend): which head is final and what its plan is (head.final), its reason phrase (phrase.line), and what each chunk-size line says (chunk.size). This module only finds those lines and copies the body's octets out (trusted below).

Trusted, not proved: packed.reply reads a response off its packed octets as Http.parse.to reads the same octets as text (laws/InterimResponsesSkipped.bend), acting on src/http.bend's decisions in order. From offset 0 it finds each head's end, the first CRLF CRLF at or after it (Bytes.find.from), at most as many heads as there are octets, and reads that head's lines as text; none is torn with the response head has no blank line after it. It skips the head when interim.skip.of says so of its status and whether any octet follows its blank line, and reads on from there; otherwise its plan is head.final of the method and its lines, and its reason phrase phrase.line of its first line (laws/ReasonPhraseFromFinalHead.bend, laws/HeadPlannedBeforeBody.bend). An Unplanned head is torn with its reason. A Planned one has its status and fields, and a body by its framing: no octets when Bare; under Sized{n}, torn with the response body stopped before its Content-Length when fewer than n octets follow the head, else exactly the first n of them (laws/ContentLengthFramesBody.bend); every octet after the head when Closed; when Chunked, the chunks from the head's end, at most as many as there are octets after it (else the chunked body is truncated): a chunk-size line with no CRLF after it ends the body; otherwise chunk.size of the line before its CRLF is acted on: SizeBad is torn with its reason, SizeLast ends the body, and SizeData{n} is torn with chunk.short() unless n octets and then CR LF follow the line's CRLF, and is otherwise exactly those n octets, the body going on at the chunk-size line after their CRLF (laws/ChunkDataUnchanged.bend). The body is the chunks' octets in order (Bytes.concat). It finds lines and copies octets out of packed Array<U32> words with bend-kit-bytes (trusted in src/wire.bend), which no law reaches. Every decision it acts on is src/http.bend's and is proved to be the text parse's: which head is final, its plan, its reason phrase and each chunk-size line's step. Over a corpus of responses (sized, short, to the close, chunked with extensions, trailers, short and non-hex chunks, TE with CL, disagreeing CLs, interim heads, 204, 304, no blank line, no status line) read by GET and HEAD, it answers exactly what Http.parse.to answers (bench/parse.bend).

3 imports
import Base
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
import ./http.bend as Http

Types

type Got source · line 50 · raw

Type

a response read off its octets: torn, or its status, its header fields and reason phrase as octet text, and its body's octets

type Parts source · line 56 · raw

Type

a chunked body's octets so far, newest first, or why it was torn

Definitions

def packed.text.of source · line 61 · raw

@r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, String)

a slice's copy as text, the buffer kept

def packed.text source · line 66 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+at:U32 -> @+n:U32 -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, String)

n octets from at as text (a head or a chunk-size line), the buffer kept

def packed.copy source · line 70 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+at:U32 -> @+n:U32 -> 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes

n octets from at, the buffer dropped

def packed.chunk.take source · line 76 · raw

@r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes) -> @+next:U32 -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @go:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> @_:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts) -> Parts

a chunk's octets copied out, then on to the chunk-size line after its CRLF

def packed.chunk.ready.is source · line 83 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+d:U32 -> @+k:U32 -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @ready:Bool -> @go:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> @_:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts) -> Parts

a chunk of k octets from d, ready when its CRLF follows them

def packed.chunk.ready source · line 93 · raw

@r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, String) -> @+d:U32 -> @+k:U32 -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @go:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> @_:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts) -> Parts

a chunk of k octets from d whose CRLF has been looked for (chunks.ready)

def packed.chunk.data source · line 101 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+d:U32 -> @+n:Nat -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @fits:Bool -> @go:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> @_:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts) -> Parts

a chunk of n octets from d: its octets must all be there, and a CRLF after them

def packed.chunk.size source · line 112 · raw

@b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+d:U32 -> @+len:U32 -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @z:0x8673751971e75cc0377d73b25bc4d890/src/http.Size -> @go:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> @_:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts) -> Parts

what a chunk-size line says, acted on with the octets after it

def packed.chunk.line source · line 125 · raw

@r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, String) -> @+d:U32 -> @+len:U32 -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @go:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> @_:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts) -> Parts

a chunk-size line read, its octets after its CRLF

def packed.chunk.at source · line 132 · raw

@r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Maybe<&2, U32>) -> @+p:U32 -> @+len:U32 -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> @go:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> @_:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts) -> Parts

a chunk-size line that ends at i, or none ends: the body ends there

def packed.chunks source · line 144 · raw

@fuel:Nat -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+p:U32 -> @+len:U32 -> @acc:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Parts

the chunks from the chunk-size line at p, at most fuel of them

def packed.chunked source · line 154 · raw

@st:U32 -> @hs:List<&2, 0x8673751971e75cc0377d73b25bc4d890/src/http.Header> -> @reason:String -> @r:Parts -> Got

a chunked body's octets in order, or why it was torn

def packed.sized source · line 165 · raw

@st:U32 -> @hs:List<&2, 0x8673751971e75cc0377d73b25bc4d890/src/http.Header> -> @reason:String -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+q:U32 -> @+n:Nat -> @short:Bool -> Got

a body framed by Content-Length: torn when fewer octets arrived

def packed.body source · line 174 · raw

@st:U32 -> @hs:List<&2, 0x8673751971e75cc0377d73b25bc4d890/src/http.Header> -> @reason:String -> @f:0x8673751971e75cc0377d73b25bc4d890/src/http.Frame -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+q:U32 -> @+len:U32 -> Got

the octets after the final head, as its framing says

def packed.final source · line 189 · raw

@p:0x8673751971e75cc0377d73b25bc4d890/src/http.Plan -> @reason:String -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+q:U32 -> @+len:U32 -> Got

the final head's plan carried out on the octets after it

def packed.step source · line 200 · raw

@+asked:Bool -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+q:U32 -> @+len:U32 -> @+ls:List<&2, String> -> @skip:Bool -> @rest:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> Got) -> Got

an interim head is skipped, any other is the final one

def packed.head.text source · line 210 · raw

@+asked:Bool -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, String) -> @+q:U32 -> @+len:U32 -> @rest:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> Got) -> Got

a head read as text, and the octets after its blank line from q

def packed.head source · line 218 · raw

@+asked:Bool -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Maybe<&2, U32>) -> @+p:U32 -> @+len:U32 -> @rest:(@_:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @_:U32 -> Got) -> Got

a head that ends at i, or none ends

def packed.heads source · line 229 · raw

@fuel:Nat -> @+asked:Bool -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> @+p:U32 -> @+len:U32 -> Got

the heads in turn from p, at most fuel of them

def packed.reply.of source · line 239 · raw

@+method:String -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, U32) -> Got

the response to a request with this method, its octets counted

def packed.reply source · line 246 · raw

@+method:String -> @b:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Got

the response to a request with this method, read off its octets as parse.to reads its text (laws/InterimResponsesSkipped.bend, laws/HeadPlannedBeforeBody.bend, trusted above)