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

Check Content-Type header for OPTIONS requests #428

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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