Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6 from rykov/master

Prevent nil headers from passing to Net::HTTP
  • Loading branch information...
commit 27e46c1bbae4af94f7de7ddc0b8282f0178c2fc5 2 parents 304aff4 + 5cdff83
@ncr authored
View
2  lib/rack/proxy.rb
@@ -49,7 +49,7 @@ def perform_request(env)
def extract_http_request_headers(env)
headers = env.reject do |k, v|
- !(/^HTTP_[A-Z_]+$/ === k)
+ !(/^HTTP_[A-Z_]+$/ === k) || v.nil?
end.map do |k, v|
[reconstruct_header_name(k), v]
end.inject(Utils::HeaderHash.new) do |hash, k_v|
View
2  test/net_http_hacked_test.rb
@@ -17,7 +17,7 @@ def test_net_http_hacked
assert headers.size > 0
assert headers["content-type"] == "text/html; charset=UTF-8"
- assert headers["content-length"].to_i > 0
+ assert !headers["date"].nil?
# Body
chunks = []
View
15 test/rack_proxy_test.rb
@@ -5,7 +5,6 @@ class RackProxyTest < Test::Unit::TestCase
class TrixProxy < Rack::Proxy
def rewrite_env(env)
env["HTTP_HOST"] = "trix.pl"
-
env
end
end
@@ -29,4 +28,18 @@ def test_header_reconstruction
header = proxy.send(:reconstruct_header_name, "HTTP_ABC_D")
assert header == "ABC-D"
end
+
+ def test_extract_http_request_headers
+ proxy = Rack::Proxy.new
+ env = {
+ 'NOT-HTTP-HEADER' => 'test-value',
+ 'HTTP_ACCEPT' => 'text/html',
+ 'HTTP_CONNECTION' => nil
+ }
+
+ headers = proxy.send(:extract_http_request_headers, env)
+ assert headers.key?('ACCEPT')
+ assert !headers.key?('CONNECTION')
+ assert !headers.key?('NOT-HTTP-HEADER')
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.