@@ -18,7 +18,7 @@ def initialize(app = nil, &b)
18
18
19
19
def call ( env )
20
20
rackreq = Rack ::Request . new ( env )
21
- matcher = get_matcher ( rackreq . fullpath , extract_http_request_headers ( rackreq . env ) , rackreq )
21
+ matcher = get_matcher ( rackreq . fullpath , Proxy . extract_http_request_headers ( rackreq . env ) , rackreq )
22
22
return @app . call ( env ) if matcher . nil?
23
23
24
24
if @global_options [ :newrelic_instrumentation ]
@@ -44,7 +44,7 @@ def proxy(env, source_request, matcher)
44
44
target_request = Net ::HTTP . const_get ( source_request . request_method . capitalize ) . new ( uri . request_uri )
45
45
46
46
# Setup headers
47
- target_request_headers = extract_http_request_headers ( source_request . env )
47
+ target_request_headers = Proxy . extract_http_request_headers ( source_request . env )
48
48
49
49
if options [ :preserve_host ]
50
50
if uri . port == uri . default_port
@@ -82,12 +82,12 @@ def proxy(env, source_request, matcher)
82
82
target_response . use_ssl = "https" == uri . scheme
83
83
84
84
# Let rack set the transfer-encoding header
85
- response_headers = format_headers ( target_response . headers )
85
+ response_headers = Rack :: Utils :: HeaderHash . new Proxy . normalize_headers ( format_headers ( target_response . headers ) )
86
86
response_headers . delete ( 'Transfer-Encoding' )
87
87
88
88
# Replace the location header with the proxy domain
89
89
if response_headers [ 'Location' ] && options [ :replace_response_host ]
90
- response_location = URI ( response_headers [ 'Location' ] [ 0 ] )
90
+ response_location = URI ( response_headers [ 'location' ] )
91
91
response_location . host = source_request . host
92
92
response_location . port = source_request . port
93
93
response_headers [ 'Location' ] = response_location . to_s
@@ -96,26 +96,6 @@ def proxy(env, source_request, matcher)
96
96
[ target_response . status , response_headers , target_response . body ]
97
97
end
98
98
99
- def extract_http_request_headers ( env )
100
- headers = env . reject do |k , v |
101
- !( /^HTTP_[A-Z_]+$/ === k ) || v . nil?
102
- end . map do |k , v |
103
- [ reconstruct_header_name ( k ) , v ]
104
- end . inject ( Utils ::HeaderHash . new ) do |hash , k_v |
105
- k , v = k_v
106
- hash [ k ] = v
107
- hash
108
- end
109
-
110
- x_forwarded_for = ( headers [ "X-Forwarded-For" ] . to_s . split ( /, +/ ) << env [ "REMOTE_ADDR" ] ) . join ( ", " )
111
-
112
- headers . merge! ( "X-Forwarded-For" => x_forwarded_for )
113
- end
114
-
115
- def reconstruct_header_name ( name )
116
- name . sub ( /^HTTP_/ , "" ) . gsub ( "_" , "-" )
117
- end
118
-
119
99
def get_matcher ( path , headers , rackreq )
120
100
matches = @matchers . select do |matcher |
121
101
matcher . match? ( path , headers , rackreq )
0 commit comments