~/bend-docscommunity

src/form.bend checks

raw source on the hub · import emerging-ezhttp@0.19.0.0/src/form.bend as Form

ezhttp/src/form: multipart/form-data request bodies (RFC 7578), no IO. A form is text fields and file parts whose content is packed Bytes. Every decision is form.plan's, over the parts with each file's content replaced by whether the delimiter occurs in it; the plan lays the body out as runs of octets and file contents, and form.build puts them together, so a file's bytes reach the wire unchanged (SPEC.md HTTP-CLI-10). The caller picks the boundary and the builder refuses one a reader could misread. SPEC.md HTTP-FORM lists what is guaranteed.

4 imports
import Base
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
import ./body.bend as Body
import ./pct.bend as Pct

Types

type Upload source · line 16 · raw

Type

one part handed to the builder: a text field, or a file with its name, content type and bytes

type Part source · line 22 · raw

Data

one part as the plan sees it: a text field, or a file whose content is known only by whether the delimiter occurs in it

type Seg source · line 27 · raw

Data

one run of the body the plan lays out: octets, or the next file's bytes

type Plan source · line 33 · raw

Data

a planned form (the Content-Type field value and the body's runs), or why not

type Form source · line 38 · raw

Type

a built form (the Content-Type field value and the body), or why not

Definitions

def form.field source · line 43 · raw

@name:String -> @value:String -> Upload

a text field

def form.file source · line 47 · raw

@name:String -> @filename:String -> @ctype:String -> @bytes:0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes -> Upload

a file part: its field name, its filename, its content type and its bytes

def octets.onto source · line 54 · raw

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

a string's UTF-8 octets in front of rest (RFC 3629 §3)

def all.step source · line 62 · raw

@ok:Bool -> @rest:(@_:Unit -> Bool) -> Bool

a check that holds when this does and the rest does: a false ends it

def any.step source · line 70 · raw

@hit:Bool -> @rest:(@_:Unit -> Bool) -> Bool

a search that hits when this does or the rest does: a true ends it

def octets.starts source · line 78 · raw

@xs:List<&2, U32> -> @pat:List<&2, U32> -> Bool

whether octets open with a pattern's octets

def octets.has source · line 90 · raw

@xs:List<&2, U32> -> @+pat:List<&2, U32> -> Bool

whether a pattern's octets occur as a contiguous run anywhere in octets

def form.bchar source · line 101 · raw

@+cp:U32 -> Bool

a boundary character this builder allows: A-Z a-z 0-9 - _ . (each a bchar of RFC 2046 and a tchar of RFC 9110 §5.6.2, so no quotes are needed)

def form.bchars source · line 109 · raw

@s:String -> Bool

every character of a string is a boundary character

def form.boundary.ok source · line 117 · raw

@+b:String -> Bool

a boundary is 1 to 70 boundary characters

def form.delim source · line 122 · raw

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

the delimiter a reader looks for: "--" and the boundary, as octets

def form.one.lf source · line 128 · raw

@+cp:U32 -> @rest:String -> @lf:Bool -> String

a character that is not " or CR: LF as %0A, anything else as itself

def form.one.cr source · line 136 · raw

@+cp:U32 -> @rest:String -> @cr:Bool -> String

a character that is not ": CR as %0D, else on to LF

def form.one.dq source · line 144 · raw

@+cp:U32 -> @rest:String -> @dq:Bool -> String

a character of a quoted name, once it is known whether it is ": as %22

def form.one source · line 152 · raw

@+cp:U32 -> @rest:String -> String

one character of a quoted name, followed by rest

def form.quote source · line 157 · raw

@s:String -> String

a name or filename as the inside of its quoted-string, as HTML's form submission writes it: ", CR and LF percent-encoded, the rest as itself

def form.disposition source · line 167 · raw

@name:String -> String

the Content-Disposition line's text up to its name parameter's end

def form.head source · line 171 · raw

@p:Part -> String

a part's header lines, each ended by CRLF (RFC 7578 §4.2, §4.4)

def form.content source · line 181 · raw

@p:Part -> @rest:List<&2, Seg> -> List<&2, Seg>

a part's content in front of rest: a field's value as UTF-8 octets, a file's bytes as they are

def form.part source · line 190 · raw

@+b:String -> @+p:Part -> @rest:List<&2, Seg> -> List<&2, Seg>

one part in front of rest: the delimiter line, its head, a blank line, its content and a CRLF

def form.parts source · line 195 · raw

@+b:String -> @ps:List<&2, Part> -> List<&2, Seg>

every part in order, then the close delimiter (RFC 2046 §5.1.1)

def form.hit source · line 206 · raw

@+b:String -> @p:Part -> Bool

whether a part's content holds the delimiter: a field's octets are searched, a file's answer was found in its bytes

def form.clash source · line 214 · raw

@+b:String -> @ps:List<&2, Part> -> Bool

whether some part's content holds the delimiter

def form.badtype.one source · line 222 · raw

@p:Part -> Bool

whether a part's content type holds a CR or an LF

def form.badtype source · line 230 · raw

@ps:List<&2, Part> -> Bool

whether any part's content type holds a CR or an LF

def form.type source · line 238 · raw

@b:String -> String

the Content-Type field value of a form with this boundary (RFC 7578 §4.1)

def form.check.type source · line 242 · raw

@+b:String -> @ps:List<&2, Part> -> @bad:Bool -> Plan

the plan once its content types are checked

def form.check.clash source · line 250 · raw

@+b:String -> @+ps:List<&2, Part> -> @hit:Bool -> Plan

the plan once its parts are checked against the delimiter

def form.check source · line 258 · raw

@+b:String -> @+ps:List<&2, Part> -> @ok:Bool -> Plan

the plan once its boundary is checked

def form.plan source · line 267 · raw

@+b:String -> @ps:List<&2, Part> -> Plan

a multipart/form-data body's plan with this boundary and these parts, or why not (SPEC.md HTTP-FORM)

def form.found source · line 273 · raw

@r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Maybe<&2, U32>) -> Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Bool)

whether a search found the delimiter, with the bytes handed back

def form.split.file source · line 283 · raw

@name:String -> @filename:String -> @ctype:String -> @r:Pair(0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes, Bool) -> @rest:Pair(List<&2, Part>, List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>) -> Pair(List<&2, Part>, List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>)

a file part once its bytes are searched: the part the plan sees, onto the rest, and its bytes kept in order

def form.split.field source · line 291 · raw

@name:String -> @value:String -> @rest:Pair(List<&2, Part>, List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>) -> Pair(List<&2, Part>, List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>)

a field part onto the rest

def form.split source · line 299 · raw

@+d:String -> @us:List<&1, Upload> -> Pair(List<&2, Part>, List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>)

the parts as the plan sees them, and the files' bytes in order; d is the delimiter's octets, one character each

def form.runs source · line 313 · raw

@segs:List<&2, Seg> -> @fs:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>

the body's runs as packed octets, each file's bytes in its place

def form.build source · line 328 · raw

@p:Plan -> @fs:List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes> -> Form

a plan as the form it builds

def form.built source · line 336 · raw

@+b:String -> @r:Pair(List<&2, Part>, List<&1, 0x185ae03c75e3e75be1171471f68b43cb/bytes.Bytes>) -> Form

a planned form once the files are searched

def form.body source · line 342 · raw

@+b:String -> @us:List<&1, Upload> -> Form

a multipart/form-data body with this boundary and these parts, or why not (SPEC.md HTTP-FORM, HTTP-TRUST-8)