Skip to main content

Crate base_web_content

Crate base_web_content 

Source
Expand description

Declarative, limited parsing of web request content, such as forms, without I/O.

Applications declare the content they accept with #[derive(Content)], with limits on every field, array, and upload, so that a body is never parsed without knowing its limits. ContentParser is fed bytes as they arrive and refuses whatever the declaration does not accept as early as the bytes allow: a name the declaration does not accept before its content is read, and any limit as soon as it is exceeded, with a fatal ContentError. Uploads are reported as events for the caller to store, and the other fields are converted strictly, with every Violation returned together when parsing finishes. The crate does no I/O.

multipart/form-data is parsed with base-web-multipart, and application/x-www-form-urlencoded with base-web-url, whose bracket paths name the fields of both. The Getting Started guide covers declarations, limits, uploads, and errors.

Structs§

Accepted
Content that parsed and satisfied its declaration.
ContentError
Why content could not be parsed at all, with the offset in the body where the parser found it.
ContentParsed
What one call to ContentParser::parse found, with the number of input bytes it consumed.
ContentParser
A sans-I/O parser for a request’s content, into the struct T declares, fed bytes as they arrive.
FieldPath
The path to a field: the declared names and array indices that lead to it.
FieldValueError
Why a field’s text could not be converted to its type. It carries no detail, since the text may be a password or personal data that must not reach logs.
Rejected
Content that was refused, with every handle the caller gave the parser, so that provisional uploads can be removed.
Upload
A file a form submitted, with the caller’s handle for where its content was stored.
UploadHead
An upload that begins: the field it is for, and what the client declared about it, which must not be trusted.
Violation
A declared field that arrived but cannot be accepted, or a required one that did not arrive.

Enums§

ContentErrorKind
The kind of ContentError.
ContentEvent
One step through a body, for the caller to act on. It is exhaustive, so that a caller can match it without a wildcard; adding an event is a breaking change.
ContentFormat
A format of request content this crate parses, chosen by the request’s media type.
FieldPathSegment
One step of a FieldPath.
ParameterRules
The rules for a Content-Disposition field’s extended parameters, such as filename*, when reading its name or filename. Forms and other MIME parts follow different RFCs, so a disposition does not choose for you.
Rejection
Why content was refused: the two kinds of failure design/errors.md defines. It is exhaustive, so that an application can match it without a wildcard; adding a kind is a breaking change.
ViolationCode
What is wrong with a field, as a Violation reports it.

Traits§

Content
Content an application declares that it accepts, with limits on everything in it. Derive it with #[derive(Content)] on a struct with named fields; it must not be implemented by hand, since what the derive implements is not public API.
ContentHandles
A declaration whose uploads hold handles of type H: any declaration without uploads, for every H, and one whose uploads are Upload<H>. It is implemented for every such declaration, so that generic code can name what ContentParser parses.
FieldValue
A field’s value converted from its submitted text, the conversion trait for scalar fields.

Derive Macros§

Content
Derive a declaration of the content a struct accepts, from its named fields.
FieldValue
Derive the conversion of an enumeration from a field’s text: the exact, case-sensitive spelling of each variant.