Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestBodyLimit custom response #417

Open
yokomizor opened this issue Sep 29, 2023 · 3 comments
Open

RequestBodyLimit custom response #417

yokomizor opened this issue Sep 29, 2023 · 3 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-middleware Topic: middleware

Comments

@yokomizor
Copy link

Feature Request

Make it possible to define the response RequestBodyLimit gives when limits are exceed.

Motivation

User facing endpoints that accept large bodies should return a response that users can understand, possibly with some tips to solve request issues. The most basic tip being "what is the limit?".

Proposal

I think it could be done either via:

  • accepting a Fn() -> Response<B> in, or
  • returning a BoxError

Alternatives

The only alternative I can think of for now is to have another layer that checks if the response status is 413, and change the response body there.

@rakshith-ravi
Copy link

Wouldn't a tower::ServiceExt::map work here?

@yokomizor
Copy link
Author

Uhm, the only way I see to change the response using ServiceExt::map is by checking if response status is 413, which works but feels fragile.

A non breaking change that could help with that is adding something like tower_http::limit::body::ResponseBody::limit_exceeded(&self) -> bool.

Then a ServiceExt::map service could use that instead of relying on response status codes.

@jplatte
Copy link
Collaborator

jplatte commented Nov 8, 2023

Given the low maintainence this project currently gets, I would recommend checking the status code for now, if you haven't already implemented that. I agree a better solution should be added though.

@jplatte jplatte added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-middleware Topic: middleware labels Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-middleware Topic: middleware
Projects
None yet
Development

No branches or pull requests

3 participants