~/bend-docscommunity

src/form.bend checks

raw source on the hub · import ezhttp@0.23.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 (laws/OctetBodiesSentUnchanged.bend). The caller picks the boundary and the builder refuses one a reader could misread. What is guaranteed is under laws/, such as laws/FormRefusesBadRequests.bend.

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 17 · 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 23 · 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 28 · raw

Data

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

type Plan source · line 34 · raw

Data

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

type Form source · line 39 · raw

Type

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

Definitions

def form.field source · line 44 · raw

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

a text field

def form.file source · line 48 · 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 55 · 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 63 · 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 71 · 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 79 · raw

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

whether octets open with a pattern's octets

def octets.has source · line 91 · 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 102 · 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 110 · raw

@s:String -> Bool

every character of a string is a boundary character

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

@+b:String -> Bool

a boundary is 1 to 70 boundary characters

def form.delim source · line 123 · raw

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

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

def form.one.lf source · line 129 · 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 137 · 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 145 · 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 153 · raw

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

one character of a quoted name, followed by rest

def form.quote source · line 158 · 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 168 · raw

@name:String -> String

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

def form.head source · line 172 · raw

@p:Part -> String

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

def form.content source · line 182 · 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 191 · 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 196 · 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 207 · 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 215 · raw

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

whether some part's content holds the delimiter

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

@p:Part -> Bool

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

def form.badtype source · line 231 · raw

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

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

def form.type source · line 239 · 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 243 · raw

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

the plan once its content types are checked

def form.check.clash source · line 251 · 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 259 · raw

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

the plan once its boundary is checked

def form.plan source · line 268 · raw

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

a multipart/form-data body's plan with this boundary and these parts, or why not (laws/FormRefusesBadRequests.bend)

def form.found source · line 284 · 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 294 · 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 302 · 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 310 · 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 324 · 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 339 · raw

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

a plan as the form it builds

def form.built source · line 347 · 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 353 · raw

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

a multipart/form-data body with this boundary and these parts, or why not (laws/FormRefusesBadRequests.bend, trusted above)