-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: return 415 when UNSUPPORTED_MEDIA_TYPE #13078
Conversation
566e217
to
7fb005a
Compare
|
||
find_content_type(#{headers := #{<<"content-type">> := Type}}) -> Type; | ||
find_content_type(#{headers := #{<<"Content-Type">> := Type}}) -> Type; | ||
find_content_type(_Headers) -> error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP RFC declares that header names are content-insensitive, this check should take it into account.
Perhaps, it can handle happy cases as implemented below, and in this clause run a more comprehensive check for pathological cases like CoNtEnT-TyPe
.
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value. Whitespace before the value is ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think cowboy normalizes header names to lower-case:
https://github.com/emqx/cowboy/blob/957dc318057b1adf1c57c021cd097d2820a13880/src/cowboy_http.erl#L605
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Then second clause is not needed.
@@ -30,6 +30,7 @@ | |||
-export([base_path/0]). | |||
-export([relative_uri/1, get_relative_uri/1]). | |||
-export([compose_filters/2]). | |||
-export([is_content_type_json/2, validate_content_type/3]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-export([is_content_type_json/2, validate_content_type/3]). | |
-export([validate_content_type_json/2, validate_content_type/3]). |
Fixes 12401
Release version: v/e5.8.0
Summary
PR Checklist
Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:
changes/(ce|ee)/(feat|perf|fix|breaking)-<PR-id>.en.md
filesChecklist for CI (.github/workflows) changes
changes/
dir for user-facing artifacts update