Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/rack_reverse_proxy/roundtrip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,34 @@ def build_response_headers
end
end

NET_HTTP_EXCEPTIONS = [
IOError,
Errno::ECONNABORTED,
Errno::ECONNREFUSED,
Errno::ECONNRESET,
Errno::EHOSTUNREACH,
Errno::EINVAL,
Errno::ENETUNREACH,
Errno::EPIPE,
Net::HTTPBadResponse,
Net::HTTPHeaderSyntaxError,
Net::ProtocolError,
SocketError,
Zlib::GzipFile::Error,
]
NET_HTTP_EXCEPTIONS << OpenSSL::SSL::SSLError if defined?(OpenSSL)
NET_HTTP_EXCEPTIONS << Net::OpenTimeout if defined?(Net::OpenTimeout)

def rack_response_headers
Rack::Utils::HeaderHash.new(
Rack::Proxy.normalize_headers(
format_headers(target_response.headers)
)
)
rescue *NET_HTTP_EXCEPTIONS => e
puts "rack-reverse-proxy rescued error from origin: #{e.class.name}: #{e.message}"
@_target_response = Struct.new(:status, :body).new(502, [])
{}
end

def replace_location_header
Expand Down