Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump deps and fix tests #101

Merged
merged 5 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ GEM
remote: https://rubygems.org/
specs:
power_assert (0.2.6)
rack (2.0.3)
rack (2.2.3)
rack-test (0.5.6)
rack (>= 1.0)
rake (13.0.1)
rake (13.0.6)
test-unit (3.1.5)
power_assert

Expand Down
16 changes: 10 additions & 6 deletions lib/rack/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ def extract_http_request_headers(env)

def normalize_headers(headers)
mapped = headers.map do |k, v|
[k, if v.is_a? Array then v.join("\n") else v end]
[titleize(k), if v.is_a? Array then v.join("\n") else v end]
end
Utils::HeaderHash.new Hash[mapped]
end

protected

def reconstruct_header_name(name)
name.sub(/^HTTP_/, "").gsub("_", "-")
titleize(name.sub(/^HTTP_/, "").gsub("_", "-"))
end

def titleize(str)
str.split("-").map(&:capitalize).join("-")
end
end

Expand All @@ -49,12 +53,12 @@ def initialize(app = nil, opts= {})

@streaming = opts.fetch(:streaming, true)
@ssl_verify_none = opts.fetch(:ssl_verify_none, false)
@backend = URI(opts[:backend]) if opts[:backend]
@backend = opts[:backend] ? URI(opts[:backend]) : nil
@read_timeout = opts.fetch(:read_timeout, 60)
@ssl_version = opts[:ssl_version] if opts[:ssl_version]
@ssl_version = opts[:ssl_version]

@username = opts[:username] if opts[:username]
@password = opts[:password] if opts[:password]
@username = opts[:username]
@password = opts[:password]

@opts = opts
end
Expand Down
19 changes: 10 additions & 9 deletions test/http_streaming_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@
class HttpStreamingResponseTest < Test::Unit::TestCase

def setup
host, req = "www.trix.pl", Net::HTTP::Get.new("/")
@response = Rack::HttpStreamingResponse.new(req, host)
host, req = "mockapi.io", Net::HTTP::Get.new("/")
@response = Rack::HttpStreamingResponse.new(req, host, 443)
@response.use_ssl = true
end

def test_streaming
# Response status
assert @response.code == 200
assert @response.status == 200
assert_equal 200, @response.status
assert_equal 200, @response.status

# Headers
headers = @response.headers

assert headers.size > 0
assert headers.size.positive?

assert headers["content-type"] == ["text/html;charset=utf-8"]
assert headers["CoNtEnT-TyPe"] == headers["content-type"]
assert headers["content-length"].first.to_i > 0
assert_match %r{text/html; ?charset=utf-8}, headers["content-type"].first.downcase
assert_equal headers["content-type"], headers["CoNtEnT-TyPe"]
assert headers["content-length"].first.to_i.positive?

# Body
chunks = []
@response.body.each do |chunk|
chunks << chunk
end

assert chunks.size > 0
assert chunks.size.positive?
chunks.each do |chunk|
assert chunk.is_a?(String)
end
Expand Down
6 changes: 3 additions & 3 deletions test/rack_proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def test_header_reconstruction
proxy_class = Rack::Proxy

header = proxy_class.send(:reconstruct_header_name, "HTTP_ABC")
assert header == "ABC"
assert header == "Abc"

header = proxy_class.send(:reconstruct_header_name, "HTTP_ABC_D")
assert header == "ABC-D"
assert header == "Abc-D"
end

def test_extract_http_request_headers
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_handles_missing_content_length
end

def test_response_header_included_Hop_by_hop
app({:streaming => true}).host = 'auth.goeasyship.com'
app({:streaming => true}).host = 'mockapi.io'
get 'https://example.com/oauth2/token/info?access_token=123'
assert !last_response.headers.key?('transfer-encoding')
end
Expand Down