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

Tracking: Improvements to DefaultBodyLimit #1409

Closed
2 of 3 tasks
davidpdrsn opened this issue Sep 24, 2022 · 7 comments
Closed
2 of 3 tasks

Tracking: Improvements to DefaultBodyLimit #1409

davidpdrsn opened this issue Sep 24, 2022 · 7 comments
Labels
A-axum A-axum-core C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Experience needed to fix: Medium / intermediate
Milestone

Comments

@davidpdrsn
Copy link
Member

davidpdrsn commented Sep 24, 2022

#1400 will remove ContentLengthLimit in favor of DefaultBodyLimit but there a few things missing on DefaultBodyLimit for it to have feature parity with ContentLengthLimit:

  • We should make sure GET, HEAD, and OPTIONS requests without a body are still accepted. This can be done by checking the content-length and if that is not there apply http_body::Limited. Then since GET, HEAD, and OPTIONS doesn't have bodies we should never hit the limit. Will be nice if that works because it removes special casing of those methods. Edit: I think we should drop this. Not really clear where to enforce this. In Router, MethodRouter, handlers, or extractors? Just checking in Router isn't enough since MethodRouter can be used without Router, and we don't wanna duplicate the check everywhere. If its really important correctness-wise then hyper should check it.
  • Currently DefaultBodyLimit has private APIs for actually enforcing the limit. This is used by Bytes::from_request. We should add a public API for that that Multipart, and other library developers, can use to get the same limiting the request of axum-core has. Could probably be a new method on RequestExt but since that isn't in axum-core it might require some exposing it there as well. Or maybe we move RequestExt to axum-core and re-export it from axum.
  • Clearly document the difference between RequestBodyLimit and DefaultBodyLimit. The difference is that DefaultBodyLimit doesn't change the request body type in Router<ReqBody> (see Middleware that change the request body have poor usability #1110). Instead if applies the checks directly in the extractors themselves. Thus its more opt-in but easier to integrate, so its a trade-off which middleware one should use.
@davidpdrsn davidpdrsn added C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Experience needed to fix: Medium / intermediate A-axum A-axum-core labels Sep 24, 2022
@davidpdrsn davidpdrsn added this to the 0.6 milestone Sep 24, 2022
@jplatte
Copy link
Member

jplatte commented Sep 26, 2022

I will take care of the second todo in the list.

@ttys3
Copy link
Contributor

ttys3 commented Sep 26, 2022

GET could have body

According moz

Sending body/payload in a GET request may cause some existing implementations to reject the request — while not prohibited by the specification, the semantics are undefined. It is better to just avoid sending payloads in GET requests.

@davidpdrsn
Copy link
Member Author

may cause some existing implementations to reject the request

That means we're allowed to reject the request, which I think we should.

@jplatte
Copy link
Member

jplatte commented Sep 26, 2022

We should make sure GET, HEAD, and OPTIONS requests without a body are still accepted. This can be done by checking the content-length and if that is not there apply http_body::Limited. Then since GET, HEAD, and OPTIONS doesn't have bodies we should never hit the limit. Will be nice if that works because it removes special casing of those methods.

Where is this special-casing happening?

@davidpdrsn
Copy link
Member Author

@jplatte
Copy link
Member

jplatte commented Sep 26, 2022

I'm afraid I still don't really understand what has to change, but maybe that's fine and you'll just do the PR to tick the first checkbox 😄

@davidpdrsn
Copy link
Member Author

I think we should just drop the first item. I elaborated a bit in the top comment.

So when #1461 is merged I think we'll be in a good place. I'll just close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-axum A-axum-core C-feature-request Category: A feature request, i.e: not implemented / a PR. E-medium Call for participation: Experience needed to fix: Medium / intermediate
Projects
None yet
Development

No branches or pull requests

3 participants