-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fairing returns incorrect Content-Length for status 204 #2821
Comments
The issue here is that the response still has a body - the client is just ignoring it. You can remove it by replacing it with an empty body: Second - I believe the For |
The OPTIONS response doesn't have a body though, That said, adding the set_sized_body() line of code does work, thanks! It's just strange to have to do this manually. Edit - and also to be pedantic, there really shouldn't be a Content-Length header at all... |
It's either your client or Hyper that's removing the body. If you read the body in the test, it's still present. |
You make me doubt my client lol! Both Python and browsers show an empty body. I just ran a Wireshark trace and it also gives an empty body. I see that the content-length is calculated in lifecycle.rs and the body isn't removed there. So I guess it must be Hyper that's removing the body? And keeping the Content-Length header and value even though it shouldn't? |
There's an open issue on this on Hyper: hyperium/hyper#2427 with a pending 3-year old PR. So yeah clearly not a Rocket thing. |
I would assume so. Hyper isn't really a web framework like Rocket - it doesn't have nearly as many checks and so forth. I think this issue should be handled by Rocket - we can add a check for a status of |
Rocket should never crash. Can you describe what you're observing? I cannot trigger a crash.
Yes, we can handle this ourselves, and I've written up a commit to do so. I'll push it once I test it a bit more. I will say I did expect hyper to handle this, as it also (ostensibly) handles a few other similar cases. It's unfortunate that the issue has gone unfixed for years in hyper. |
Rocket Version
0.5.1
Operating System
Windows 10
Rust Toolchain Version
rustc 1.79.0 (129f3b996 2024-06-10)
What happened?
When adding a fairing to handle CORS requests, the Content-Length header is not updated. When you run the example server below and then check the returned headers, e.g. with Python
it gives
I suspect the 'content-length': '435' comes from the length of the default 404 page in Rocket. However for a 204 No Content the RFC says
There is no way to manually set this header in Rocket and trying to override it in the Fairing results in a runtime crash.
It's a really minor thing and browsers don't seem to care, but I found it strange that an OPTIONS request returned a header with Content-Length: 435 so I dug a bit deeper.
I could manually add an OPTIONS route for each existing endpoint to avoid the internal redirect to the default 404 page, but
Note, when trying to find these headers via the Rocket test Client I don't get all the actual headers (e.g. Date and Content-Length are not included), I'm probably doing something wrong.
Test Case
Log Output
Additional Context
No response
System Checks
rustc
toolchain.The text was updated successfully, but these errors were encountered: