Skip to content

Commit df3184e

Browse files
authored
Merge pull request #27 from kylewlacy/passthrough-compression
Add option to pass through compression
2 parents a18114a + 46eaa86 commit df3184e

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

lib/reverse_proxy/client.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,25 @@ def initialize(url)
3737

3838
def request(env, options = {}, &block)
3939
options.reverse_merge!(
40-
headers: {},
41-
http: {},
42-
path: nil,
43-
username: nil,
44-
password: nil,
45-
verify_ssl: true
40+
headers: {},
41+
http: {},
42+
path: nil,
43+
username: nil,
44+
password: nil,
45+
verify_ssl: true,
46+
reset_accept_encoding: false
4647
)
4748

4849
source_request = Rack::Request.new(env)
4950

5051
# We can pass in a custom path
5152
uri = Addressable::URI.parse("#{url}#{options[:path] || env['ORIGINAL_FULLPATH']}")
5253

53-
# Initialize request
54-
target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(uri.request_uri)
55-
56-
# Setup headers
54+
# Define headers
5755
target_request_headers = extract_http_request_headers(source_request.env).merge(options[:headers])
5856

59-
target_request.initialize_http_header(target_request_headers)
57+
# Initialize request
58+
target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(uri.request_uri, target_request_headers)
6059

6160
# Basic auth
6261
target_request.basic_auth(options[:username], options[:password]) if options[:username] and options[:password]
@@ -74,11 +73,11 @@ def request(env, options = {}, &block)
7473
# Hold the response here
7574
target_response = nil
7675

77-
# Don't encode response/support compression which was
78-
# causing content length not match the actual content
79-
# length of the response which ended up causing issues
80-
# within Varnish (503)
81-
target_request['Accept-Encoding'] = nil
76+
if options[:reset_accept_encoding]
77+
# Clear the "Accept-Encoding" header (which will
78+
# disable compression or other server-side encodings)
79+
target_request['Accept-Encoding'] = nil
80+
end
8281

8382
http_options = {}
8483
http_options[:use_ssl] = (uri.scheme == "https")

0 commit comments

Comments
 (0)