Skip to content

Commit

Permalink
Allow nil path, and convert path to string in Request.[].
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 29, 2025
1 parent 32786bf commit 4f6af15
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/protocol/http/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def self.each
end

self.each do |name, method|
define_method(name) do |location, *arguments, **options|
define_method(name) do |*arguments, **options|
self.call(
Request[method, location.to_s, *arguments, **options]
Request[method, *arguments, **options]
)
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/protocol/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def connect?
# @parameter path [String] The path, e.g. `"/index.html"`, `"/search?q=hello"`, etc.
# @parameter headers [Hash] The headers, e.g. `{"accept" => "text/html"}`, etc.
# @parameter body [String | Array(String) | Body::Readable] The body, e.g. `"Hello, World!"`, etc. See {Body::Buffered.wrap} for more information about .
def self.[](method, path, _headers = nil, _body = nil, scheme: nil, authority: nil, headers: _headers, body: _body, protocol: nil, interim_response: nil)
def self.[](method, path = nil, _headers = nil, _body = nil, scheme: nil, authority: nil, headers: _headers, body: _body, protocol: nil, interim_response: nil)
path = path&.to_s
body = Body::Buffered.wrap(body)
headers = Headers[headers]

Expand Down
18 changes: 18 additions & 0 deletions test/protocol/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@
body: be_a(Protocol::HTTP::Body::Buffered)
)
end

it "can accept no arguments" do
request = subject["GET"]

expect(request).to have_attributes(
method: be == "GET",
path: be_nil,
)
end

it "converts path to string" do
request = subject["GET", :index]

expect(request).to have_attributes(
method: be == "GET",
path: be == "index",
)
end
end

with "simple GET request" do
Expand Down

0 comments on commit 4f6af15

Please sign in to comment.