base-web-content
Declarative, limited parsing of web request content, such as forms, without I/O, for Rust.
Applications declare the content they accept, as multipart/form-data or application/x-www-form-urlencoded, with #[derive(Content)], with a limit on every field, array, and upload, so that a server never parses a body without knowing its limits. The parser is fed bytes as they arrive and refuses whatever the declaration does not accept as early as the bytes allow: an undeclared name before its content is read, and any limit as soon as it is exceeded. Uploads are streamed to storage the caller owns, and fields are converted strictly into the declared struct, with every invalid field reported together.
Usage
use ;
use MediaType;
let media_type = parse?;
let body = b"--XyZ\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\nada\r\n--XyZ\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\nhunter2\r\n--XyZ--\r\n";
let mut parser = new?;
// With the whole body in memory, its end is known: parse until the parser reports it.
let mut input = &body;
loop
match parser.finish
# Ok::
See the Getting Started guide for declarations, limits, uploads, and errors.
Releases
See releases.md.
See Also
- Protocol::Content, the Ruby gem this crate follows.
base-web-multipart, which frames the multipart bodies of forms.base-web-url, which reads URL-encoded forms and the bracket paths of field names.base-web-media-type, which reads the media types that choose a format and that uploads accept.
Contributing
Please open an issue or pull request on GitHub.
Install the Bake launcher and run cargo bake test. Use cargo bake test:coverage --all-targets true for the shared source-region coverage gate.
Agent Context
Run cargo bake agent:context:install to install shared context and skills. Use cargo bake agent:context:list and cargo bake agent:context:show to discover relevant guides, follow repository guidance in .agents/, and apply skills under .agents/skills/.
Before planning or changing behavior, discover and read applicable design/*.md. Use base-design-review to assess plans and changes, and base-design-author when user requirements are introduced, changed, or removed. Review design compliance before opening or updating a pull request.