You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I a route defines a content type consumed by it, the header Content-Type of a request is checked. In case the type does not match one of the accepted, the error 415 Unsupported Media Type is returned. In case, the header is not given or empty, the error 400 Bad Request is returned. IMO the latter is wrong. An empty content type header should also return a 415 because it clearly indicates that the content type is faulty while a 400 is very vague. Especially, if there is no error message. Took me a while to understand that this is the problem when we were testing a new endpoint.
The mdn web docs also describe that a 415 should be returned if the header is missing. Additionally, it describes that the Accept-Post header in the response shoud be set to the accepted types. The RFC 9110 does not distinguish between empty and mismatched types but also states that an Accept header should be returned.
The piece of code handling this was introduced in #456. This is the piece of code in the class io.vertx.ext.web.impl.RouteState:
if (!isEmpty(consumes)) {
// Can this route consume the specified content typeMIMEHeadercontentType = context.parsedHeaders().contentType();
MIMEHeaderconsumal = contentType.findMatchedBy(consumes);
if (consumal == null && !(contentType.rawValue().isEmpty() && emptyBodyPermittedWithConsumes)) {
if (contentType.rawValue().isEmpty()) {
return400;
} else {
return415;
}
}
}
The return of a 400 should be removed. Instead, always return a 415 if the route defines consumed content types and the given type in the request is missing or does not match. The header Accept should also be returned with the accepted types.
Do you have a reproducer?
No.
Steps to reproduce
Create a route with a consumed content type.
Send a request to this endpoint without a Content-Type header.
Extra
None.
The text was updated successfully, but these errors were encountered:
Version
Since v.3.8.0
Context
I a route defines a content type consumed by it, the header
Content-Type
of a request is checked. In case the type does not match one of the accepted, the error415 Unsupported Media Type
is returned. In case, the header is not given or empty, the error400 Bad Request
is returned. IMO the latter is wrong. An empty content type header should also return a 415 because it clearly indicates that the content type is faulty while a 400 is very vague. Especially, if there is no error message. Took me a while to understand that this is the problem when we were testing a new endpoint.The mdn web docs also describe that a 415 should be returned if the header is missing. Additionally, it describes that the
Accept-Post
header in the response shoud be set to the accepted types. The RFC 9110 does not distinguish between empty and mismatched types but also states that anAccept
header should be returned.The piece of code handling this was introduced in #456. This is the piece of code in the class
io.vertx.ext.web.impl.RouteState
:The return of a 400 should be removed. Instead, always return a 415 if the route defines consumed content types and the given type in the request is missing or does not match. The header
Accept
should also be returned with the accepted types.Do you have a reproducer?
No.
Steps to reproduce
Content-Type
header.Extra
None.
The text was updated successfully, but these errors were encountered: