Skip to content

Commit

Permalink
rack 3 initial attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
pcai committed Feb 11, 2024
1 parent a67e021 commit 8bedc7a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gem 'net-http-persistent', '~> 4.0', :require => false
gem 'http', :require => false

# adapter extensions
gem 'rack', '< 3'
gem 'rack'
gem 'socksify'

# coverage
Expand Down
4 changes: 2 additions & 2 deletions httpi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|

s.license = 'MIT'

s.add_dependency 'rack', '< 3'
s.add_dependency 'rack', '>= 2.0', '< 3.1'
s.add_dependency 'nkf'
s.add_dependency 'base64'
s.add_dependency 'mutex_m'
Expand All @@ -30,7 +30,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.5'
s.add_development_dependency 'mocha', '~> 0.13'
s.add_development_dependency 'puma', '~> 5.0'
s.add_development_dependency 'puma', '~> 6.0'
s.add_development_dependency 'webmock'

s.metadata["rubygems_mfa_required"] = "true"
Expand Down
4 changes: 2 additions & 2 deletions lib/httpi/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def ssl?

# Returns a Hash of HTTP headers. Defaults to return an empty Hash.
def headers
@headers ||= Rack::Utils::HeaderHash.new
@headers ||= Rack::Headers.new
end

# Sets the Hash of HTTP headers.
def headers=(headers)
@headers = Rack::Utils::HeaderHash.new(headers)
@headers = Rack::Headers.new.merge(headers)
end

# Adds a header information to accept gzipped content.
Expand Down
2 changes: 1 addition & 1 deletion lib/httpi/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Response
# Initializer expects an HTTP response +code+, +headers+ and +body+.
def initialize(code, headers, body)
self.code = code.to_i
self.headers = Rack::Utils::HeaderHash.new(headers)
self.headers = Rack::Headers.new.merge(headers)
self.raw_body = body
end

Expand Down
8 changes: 4 additions & 4 deletions spec/httpi/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
after { HTTPI.query_builder = :flat }

it "lets you specify query parameter as Hash" do
expect(request.url.to_s).to eq("http://example.com?q[]=nested&q[]=query")
expect(request.url.to_s).to eq("http://example.com?q%5B%5D=nested&q%5B%5D=query")
end

it "getter return String for query parameter as Hash" do
expect(request.query).to eq("q[]=nested&q[]=query")
expect(request.query).to eq("q%5B%5D=nested&q%5B%5D=query")
end
end
end
Expand Down Expand Up @@ -149,7 +149,7 @@
describe "#headers" do
it "lets you specify a Hash of HTTP request headers" do
request.headers = { "Accept-Encoding" => "gzip" }
expect(request.headers).to eq({ "Accept-Encoding" => "gzip" })
expect(request.headers).to eq Rack::Headers.new.merge({ "Accept-Encoding" => "gzip" })
end

it "defaults to return an empty Hash" do
Expand Down Expand Up @@ -235,7 +235,7 @@ def response_with_cookie(cookie)
end
it "request body using a Hash with Array" do
request.body = {:foo => :bar, :baz => [:foo, :tst]}
expect(request.body.split("&")).to match_array(["foo=bar", "baz[]=foo", "baz[]=tst"])
expect(request.body.split("&")).to match_array(["foo=bar", "baz%5B%5D=foo", "baz%5B%5D=tst"])
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/httpi/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

describe "#headers" do
it "returns the HTTP response headers" do
expect(response.headers).to eq({ "Content-Encoding" => "gzip" })
expect(response.headers).to eq Rack::Headers.new.merge({ "Content-Encoding" => "gzip" })
end
end

Expand Down Expand Up @@ -116,7 +116,7 @@

describe "#headers" do
it "returns the HTTP response headers" do
expect(response.headers).to eq({ "Content-Type" => "application/dime" })
expect(response.headers).to eq Rack::Headers.new.merge({ "Content-Type" => "application/dime" })
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/support/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def stop
private

def events
Puma::Events.new($stdout, $stderr)
Puma::Events.new
end

def add_tcp_listener
Expand Down

0 comments on commit 8bedc7a

Please sign in to comment.