Class: RubyProxyHeaders::FaradayAdapter::NetHttp

Inherits:
Faraday::Adapter::NetHttp
  • Object
show all
Defined in:
lib/ruby_proxy_headers/faraday.rb

Overview

Copies CONNECT response headers onto the Faraday response.

Instance Method Summary collapse

Instance Method Details

#build_connection(env) ⇒ Object



24
25
26
# File 'lib/ruby_proxy_headers/faraday.rb', line 24

def build_connection(env)
  super.tap { |http| Thread.current[:ruby_proxy_headers_faraday_http] = http }
end

#call(env) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_proxy_headers/faraday.rb', line 28

def call(env)
  response = super
  http = Thread.current[:ruby_proxy_headers_faraday_http]
  headers = http.last_proxy_connect_response_headers if http
  if env[:response_headers] && headers
    headers.each do |key, value|
      next if value.nil?

      env[:response_headers][key] ||= value
    end
  end
  response
ensure
  Thread.current[:ruby_proxy_headers_faraday_http] = nil
end