src/form.bend checks
raw source on the hub · import emerging-ezhttp@0.17.0.0/src/form.bend as Form
ezhttp/src/form: multipart/form-data request bodies (RFC 7578), pure. A form is text fields and file parts; the body is octets (Body.Octets), 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.
3 imports
import Base import ./body.bend as Body import ./pct.bend as Pct
Types
type Part source · line 11 · raw
Data
one part of a form: a text field, or a file with its name and content type
Field@name:String -> @value:String -> Part
File@name:String -> @filename:String -> @ctype:String -> @bytes:List<&2, U32> -> Part
type Form source · line 16 · raw
Data
a built form (the Content-Type field value and the body), or why not
NoForm@why:String -> Form
Form@ctype:String -> @body:0x2c3360c0ff9d38b16f7c5d3da25532d7/src/body.Body -> Form
Definitions
def form.field source · line 21 · raw
@name:String -> @value:String -> Part
a text field
def form.file source · line 26 · raw
@name:String -> @filename:String -> @ctype:String -> @bytes:List<&2, U32> -> Part
a file part: its field name, its filename, its content type and its bytes (each 0..255)
def octets.onto source · line 33 · 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 41 · 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 49 · 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 57 · raw
@xs:List<&2, U32> -> @pat:List<&2, U32> -> Bool
whether octets open with a pattern's octets
def octets.has source · line 69 · 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 80 · 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 88 · raw
@s:String -> Bool
every character of a string is a boundary character
def form.boundary.ok source · line 96 · raw
@+b:String -> Bool
a boundary is 1 to 70 boundary characters
def form.delim source · line 101 · raw
@b:String -> List<&2, U32>
the delimiter a reader looks for: "--" and the boundary, as octets
def form.one.lf source · line 107 · 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 115 · 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 123 · 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 131 · raw
@+cp:U32 -> @rest:String -> String
one character of a quoted name, followed by rest
def form.quote source · line 136 · 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 146 · raw
@name:String -> String
the Content-Disposition line's text up to its name parameter's end
def form.head source · line 150 · raw
@p:Part -> String
a part's header lines, each ended by CRLF (RFC 7578 §4.2, §4.4)
def form.content source · line 160 · raw
@p:Part -> @rest:List<&2, U32> -> List<&2, U32>
a part's content in front of rest: a field's value as UTF-8, a file's
bytes as they are
def form.part source · line 169 · raw
@+b:String -> @+p:Part -> @rest:List<&2, U32> -> List<&2, U32>
one part in front of rest: the delimiter line, its head, a blank line,
its content and a CRLF
def form.parts source · line 174 · raw
@+b:String -> @ps:List<&2, Part> -> List<&2, U32>
every part in order, then the close delimiter (RFC 2046 §5.1.1)
def form.clash source · line 184 · raw
@+b:String -> @ps:List<&2, Part> -> Bool
whether some part's content holds the delimiter
def form.badtype.one source · line 193 · raw
@p:Part -> Bool
whether a part's content type holds a CR or an LF
def form.badtype source · line 201 · raw
@ps:List<&2, Part> -> Bool
whether any part's content type holds a CR or an LF
def form.type source · line 209 · 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 213 · raw
@+b:String -> @ps:List<&2, Part> -> @bad:Bool -> Form
the form once its content types are checked
def form.check.clash source · line 221 · raw
@+b:String -> @+ps:List<&2, Part> -> @hit:Bool -> Form
the form once its parts are checked against the delimiter
def form.check source · line 229 · raw
@+b:String -> @+ps:List<&2, Part> -> @ok:Bool -> Form
the form once its boundary is checked
def form.body source · line 238 · raw
@+b:String -> @ps:List<&2, Part> -> Form
a multipart/form-data body with this boundary and these parts, or why not (SPEC.md HTTP-FORM)