Skip to content

Commit f480d5c

Browse files
Add test for OPTIONS * handling.
1 parent c263672 commit f480d5c

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

gems/passenger-v6-rack-v2.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
# export RACK_CONFORM_SERVER="passenger start"
1515
# export RACK_CONFORM_ENDPOINT="http://127.0.0.1:3000"
16+
17+
RACK_CONFORM_BROKEN = [:options_star]

gems/webrick-rack-v3.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
eval_gemfile "../gems.rb"
77

8-
gem "rack", "~> 3.0.1"
8+
gem "rack", "~> 3.2"
99
gem "webrick"
1010
gem "rackup"
11+
12+
# export RACK_CONFORM_SERVER="rackup -s webrick"
13+
# export RACK_CONFORM_ENDPOINT="http://127.0.0.1:9292"

lib/rack/conform.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@
55

66
require_relative "conform/version"
77
require_relative "conform/application"
8+
9+
module Rack
10+
module Conform
11+
def self.broken?(feature)
12+
if defined?(RACK_CONFORM_BROKEN)
13+
RACK_CONFORM_BROKEN&.include?(feature)
14+
else
15+
false
16+
end
17+
end
18+
end
19+
end

lib/rack/conform/application.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_middleware_body_itself(env)
114114
Middleware::BodyItself.new(self).call(env)
115115
end
116116

117-
def test_options_star(env)
117+
def test_options(env)
118118
request_method = env["REQUEST_METHOD"]
119119
path_info = env["PATH_INFO"]
120120

@@ -129,7 +129,7 @@ def test_method_for(env)
129129

130130
# Special case for OPTIONS * request:
131131
if request_method == "OPTIONS"
132-
return :test_options_star
132+
return :test_options
133133
end
134134

135135
parts = path_info.split("/")

test/rack/conform/options_star.rb renamed to test/rack/conform/options.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Released under the MIT License.
44
# Copyright, 2024, by Samuel Williams.
55

6+
require "rack/conform"
7+
68
require "client_context"
79
include ClientContext
810

@@ -19,3 +21,19 @@
1921
ensure
2022
response&.finish
2123
end
24+
25+
it "can handle OPTIONS * request" do
26+
skip if ::Rack::Conform.broken?(:options_star)
27+
28+
request = Protocol::HTTP::Request.new(
29+
endpoint.scheme, endpoint.authority, "OPTIONS", "*", nil, Protocol::HTTP::Headers.new, nil
30+
)
31+
32+
response = client.call(request)
33+
expect(response.status).to be == 200
34+
if ::Rack::RELEASE > "3.0"
35+
expect(response.read).to be(:start_with?, "OPTIONS *")
36+
end
37+
ensure
38+
response&.finish
39+
end

0 commit comments

Comments
 (0)