expression

Axum: reject a missing multipart boundary

The parser needs the boundary parameter to identify the individual parts. A multipart header without a usable boundary is invalid; the extractor rejects it before the handler runs. The test prints only the response status, not parser diagnostics. In-memory standalone Cargo example. Expected stdout (not executed): 400 Common mistake: Manually setting a multipart header without the corresponding boundary.

Formal Syntax & Structure

rust syntaxrust
Content-Type: multipart/form-data; boundary=...

Working Example

Example Snippetrust
use axum::{Router, body::{Body, to_bytes}, http::{Request, StatusCode}};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() {    use axum::{extract::Multipart, routing::post, http::header};    let app = Router::new().route("/upload", post(|_: Multipart| async { StatusCode::OK }));    let req = Request::builder().method("POST").uri("/upload")        .header(header::CONTENT_TYPE, "multipart/form-data").body(Body::from("invalid")).unwrap();    let r = app.oneshot(req).await.unwrap();    println!("{}", r.status().as_u16());}
Rust Reference