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

feat: return 415 when UNSUPPORTED_MEDIA_TYPE #13078

Merged
merged 3 commits into from
May 24, 2024

Conversation

zhongwencool
Copy link
Contributor

@zhongwencool zhongwencool commented May 21, 2024

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:

  • Added tests for the changes
  • Added property-based tests for code which performs user input validation
  • Changed lines covered in coverage report
  • Change log has been added to changes/(ce|ee)/(feat|perf|fix|breaking)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • Created PR to emqx-docs if documentation update is required, or link to a follow-up jira ticket
  • Schema changes are backward compatible

Checklist for CI (.github/workflows) changes

  • If changed package build workflow, pass this action (manual trigger)
  • Change log has been added to changes/ dir for user-facing artifacts update


find_content_type(#{headers := #{<<"content-type">> := Type}}) -> Type;
find_content_type(#{headers := #{<<"Content-Type">> := Type}}) -> Type;
find_content_type(_Headers) -> error.
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-export([is_content_type_json/2, validate_content_type/3]).
-export([validate_content_type_json/2, validate_content_type/3]).

@zhongwencool zhongwencool merged commit e5da4aa into emqx:master May 24, 2024
175 of 177 checks passed
@zhongwencool zhongwencool deleted the http-415 branch May 24, 2024 07:59
@emqxqa
Copy link

emqxqa commented Jun 14, 2024

TestExecution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants