Add option to pass through compressed responses
This commit is contained in:
parent
c9336a23d3
commit
5662cc2bde
|
@ -65,6 +65,14 @@ If you'd like to bypass SSL verification
|
||||||
reverse_proxy "http://localhost:8000", verify_ssl: false
|
reverse_proxy "http://localhost:8000", verify_ssl: false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you'd like to allow the proxy to request compressed resources by forwarding the `Accept-Encoding` header
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
reverse_proxy "http://localhost:8000", compression: :passthrough
|
||||||
|
# Note that your controller's response will only be compressed
|
||||||
|
# if the original response from localhost:8000 is compressed!
|
||||||
|
```
|
||||||
|
|
||||||
If you'd like to customize the options passed into the [HTTP session](https://ruby-doc.org/stdlib-2.4.0/libdoc/net/http/rdoc/Net/HTTP.html#start-method)
|
If you'd like to customize the options passed into the [HTTP session](https://ruby-doc.org/stdlib-2.4.0/libdoc/net/http/rdoc/Net/HTTP.html#start-method)
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
|
|
@ -43,7 +43,8 @@ module ReverseProxy
|
||||||
path: nil,
|
path: nil,
|
||||||
username: nil,
|
username: nil,
|
||||||
password: nil,
|
password: nil,
|
||||||
verify_ssl: true
|
verify_ssl: true,
|
||||||
|
compression: :disabled
|
||||||
)
|
)
|
||||||
|
|
||||||
source_request = Rack::Request.new(env)
|
source_request = Rack::Request.new(env)
|
||||||
|
@ -73,11 +74,14 @@ module ReverseProxy
|
||||||
# Hold the response here
|
# Hold the response here
|
||||||
target_response = nil
|
target_response = nil
|
||||||
|
|
||||||
# Don't encode response/support compression which was
|
case options[:compression]
|
||||||
# causing content length not match the actual content
|
when :passthrough
|
||||||
# length of the response which ended up causing issues
|
# Pass along the "Accept-Encoding" header from the source request as-is,
|
||||||
# within Varnish (503)
|
# so we don't need to change anything
|
||||||
|
when :disabled, false, nil
|
||||||
|
# Remove the "Accept-Encoding" header if compression is disabled
|
||||||
target_request['Accept-Encoding'] = nil
|
target_request['Accept-Encoding'] = nil
|
||||||
|
end
|
||||||
|
|
||||||
http_options = {}
|
http_options = {}
|
||||||
http_options[:use_ssl] = (uri.scheme == "https")
|
http_options[:use_ssl] = (uri.scheme == "https")
|
||||||
|
|
Loading…
Reference in New Issue