Skip to content

Commit 61c918b

Browse files
authoredOct 9, 2024··
Check Content-Type header for OPTIONS requests (#428)
1 parent f19c4ad commit 61c918b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎lib/committee/schema_validator/open_api_3/request_validator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def call(request, path_params, query_params, body_params, headers)
2121
private
2222

2323
def check_content_type(request, content_type)
24-
# support post, put, patch only
25-
return true unless request.post? || request.put? || request.patch?
24+
# support post, put, patch, options only
25+
return true unless request.post? || request.put? || request.patch? || request.options?
2626
return true if @operation_object.valid_request_content_type?(content_type)
2727
return true if @operation_object.optional_body? && empty_request?(request)
2828

‎test/schema_validator/open_api_3/request_validator_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ def app
9595
assert_equal 400, last_response.status
9696
end
9797

98+
it "validates content_type for option request" do
99+
@app = new_rack_app(check_content_type: true, schema: open_api_3_schema)
100+
header "Content-Type", "text/html"
101+
options "/validate", "{}"
102+
assert_equal 400, last_response.status
103+
end
104+
98105
def new_rack_app(options = {})
99106
Rack::Builder.new {
100107
use Committee::Middleware::RequestValidation, options

0 commit comments

Comments
 (0)
Please sign in to comment.