Skip to content

Multipart handler not respecting RequestBodyLimitLayer adjustment #1666

Answered by sneakycrow
sneakycrow asked this question in Q&A
Discussion options

You must be logged in to vote

I was able to get it to respect the RequestBodyLimitLayer by disabling the DefaultBodyLimit in the layer before, like this:

    let app: Router = Router::new()
        .merge(index)
        .route("/upload", post(upload))
        .layer(DefaultBodyLimit::disable())
        .layer(RequestBodyLimitLayer::new(CONTENT_LENGTH_LIMIT));

Is this intended functionality? I didn't see this being a requirement in any examples.

Edit:

Per @jplatte's suggestion, this works too and is much cleaner:

    let app: Router = Router::new()
        .merge(index)
        .route("/upload", post(upload))
        .layer(DefaultBodyLimit::max(CONTENT_LENGTH_LIMIT));

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@sneakycrow
Comment options

@davidpdrsn
Comment options

@sneakycrow
Comment options

Comment options

You must be logged in to vote
3 replies
@davidpdrsn
Comment options

@jplatte
Comment options

@sneakycrow
Comment options

Answer selected by sneakycrow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants