-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
Incorrect error response when content-length header is missing #2020
Comments
Just trying to follow this, I looked at the function and see this at line 128:
Are you sure the 400/Bad Request response is raised even if the body is present? Can you show a way to reproduce this, possibly with a clever curl invocation? |
Curl does add the content-length by default. I can force it not to add the content-length by specifying Default CURL (will add Content-Length header): Response: CURL without Content-Length header (explicit removal): Response: Logs of the server: For instance, the spring framework also does not add content-length headers in some versions: spring-projects/spring-framework#32816 (comment) |
Thanks for the report @chrismathias! This is not an easy fix though, since we use the Another less complex way to tackle this would be to still raise a 400, but change the message to "Request body is empty or content-length is missing". |
If we do want to go for the more correct but more complex solution, we should probably:
|
I'm leaning more towards the simple solution currently. |
Description
In the validator https://github.com/spec-first/connexion/blob/main/connexion/validators/abstract.py#L126 a http status code 400 error is raised if content-length header is missing or 0 when a request body is present. The server response is then "RequestBody is required", which is confusing, as the request body does exist.
Expected behaviour
According to https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2 the correct server response should be http status code 411 "Length Required", ideally identifying that body was present but content-length not set or 0. Ideally, the error message would indicate "content-length header missing or 0".
Actual behaviour
Server response to missing content-length header or header with value 0 is 400 "RequestBody is required".
Steps to reproduce
Send http POST with body but missing content-length or content-length 0.
Additional info:
Output of the commands:
python --version
: Python 3.10.12pip show connexion | grep "^Version\:"
Version: 3.1.0The text was updated successfully, but these errors were encountered: