@@ -13,7 +13,7 @@ def initialize(app = nil, &b)
13
13
@app = app || lambda { |env | [ 404 , [ ] , [ ] ] }
14
14
@matchers = [ ]
15
15
@global_options = { :preserve_host => true , :x_forwarded_host => true , :matching => :all , :replace_response_host => false }
16
- instance_eval & b if block_given?
16
+ instance_eval ( & b ) if block_given?
17
17
end
18
18
19
19
def call ( env )
@@ -82,15 +82,15 @@ 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 = target_response . headers
86
- response_headers . delete ( 'transfer-encoding ' )
85
+ response_headers = format_headers ( target_response . headers )
86
+ response_headers . delete ( 'Transfer-Encoding ' )
87
87
88
88
# Replace the location header with the proxy domain
89
- if response_headers [ 'location ' ] && options [ :replace_response_host ]
90
- response_location = URI ( response_headers [ 'location ' ] [ 0 ] )
89
+ if response_headers [ 'Location ' ] && options [ :replace_response_host ]
90
+ response_location = URI ( response_headers [ 'Location ' ] [ 0 ] )
91
91
response_location . host = source_request . host
92
92
response_location . port = source_request . port
93
- response_headers [ 'location ' ] = response_location . to_s
93
+ response_headers [ 'Location ' ] = response_location . to_s
94
94
end
95
95
96
96
[ target_response . status , response_headers , target_response . body ]
@@ -138,5 +138,13 @@ def reverse_proxy(matcher, url=nil, opts={})
138
138
raise GenericProxyURI . new ( url ) if matcher . is_a? ( String ) && url . is_a? ( String ) && URI ( url ) . class == URI ::Generic
139
139
@matchers << ReverseProxyMatcher . new ( matcher , url , opts )
140
140
end
141
+
142
+ def format_headers ( headers )
143
+ headers . reduce ( { } ) do |acc , ( key , val ) |
144
+ formated_key = key . split ( '-' ) . map ( &:capitalize ) . join ( '-' )
145
+ acc [ formated_key ] = Array ( val )
146
+ acc
147
+ end
148
+ end
141
149
end
142
150
end
0 commit comments