Skip to content

Commit

Permalink
Check Content-Type header for OPTIONS requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flixt committed Sep 11, 2024
1 parent 417cc2f commit 3d09789
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def call(request, path_params, query_params, body_params, headers)
private

def check_content_type(request, content_type)
# support post, put, patch only
return true unless request.post? || request.put? || request.patch?
# support post, put, patch, options only
return true unless request.post? || request.put? || request.patch? || request.options?
return true if @operation_object.valid_request_content_type?(content_type)
return true if @operation_object.optional_body? && empty_request?(request)

Expand Down
7 changes: 7 additions & 0 deletions test/schema_validator/open_api_3/request_validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def app
assert_equal 400, last_response.status
end

it "validates content_type for option request" do
@app = new_rack_app(check_content_type: true, schema: open_api_3_schema)
header "Content-Type", "text/html"
options "/validate", "{}"
assert_equal 400, last_response.status
end

def new_rack_app(options = {})
Rack::Builder.new {
use Committee::Middleware::RequestValidation, options
Expand Down

0 comments on commit 3d09789

Please sign in to comment.