Skip to content

Commit 4f6af15

Browse files
committed
Allow nil path, and convert path to string in Request.[].
1 parent 32786bf commit 4f6af15

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lib/protocol/http/methods.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def self.each
7575
end
7676

7777
self.each do |name, method|
78-
define_method(name) do |location, *arguments, **options|
78+
define_method(name) do |*arguments, **options|
7979
self.call(
80-
Request[method, location.to_s, *arguments, **options]
80+
Request[method, *arguments, **options]
8181
)
8282
end
8383
end

lib/protocol/http/request.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def connect?
124124
# @parameter path [String] The path, e.g. `"/index.html"`, `"/search?q=hello"`, etc.
125125
# @parameter headers [Hash] The headers, e.g. `{"accept" => "text/html"}`, etc.
126126
# @parameter body [String | Array(String) | Body::Readable] The body, e.g. `"Hello, World!"`, etc. See {Body::Buffered.wrap} for more information about .
127-
def self.[](method, path, _headers = nil, _body = nil, scheme: nil, authority: nil, headers: _headers, body: _body, protocol: nil, interim_response: nil)
127+
def self.[](method, path = nil, _headers = nil, _body = nil, scheme: nil, authority: nil, headers: _headers, body: _body, protocol: nil, interim_response: nil)
128+
path = path&.to_s
128129
body = Body::Buffered.wrap(body)
129130
headers = Headers[headers]
130131

test/protocol/http/request.rb

+18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@
6060
body: be_a(Protocol::HTTP::Body::Buffered)
6161
)
6262
end
63+
64+
it "can accept no arguments" do
65+
request = subject["GET"]
66+
67+
expect(request).to have_attributes(
68+
method: be == "GET",
69+
path: be_nil,
70+
)
71+
end
72+
73+
it "converts path to string" do
74+
request = subject["GET", :index]
75+
76+
expect(request).to have_attributes(
77+
method: be == "GET",
78+
path: be == "index",
79+
)
80+
end
6381
end
6482

6583
with "simple GET request" do

0 commit comments

Comments
 (0)