Module: RubyProxyHeaders::NetHTTP::Extension

Defined in:
lib/ruby_proxy_headers/net_http.rb

Overview

Instance methods prepended onto Net::HTTP.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_proxy_connect_response_headers ⇒ Object

Returns the value of attribute last_proxy_connect_response_headers.



74
75
76
# File 'lib/ruby_proxy_headers/net_http.rb', line 74

def last_proxy_connect_response_headers
  @last_proxy_connect_response_headers
end

#proxy_connect_request_headers ⇒ Object

Returns the value of attribute proxy_connect_request_headers.



74
75
76
# File 'lib/ruby_proxy_headers/net_http.rb', line 74

def proxy_connect_request_headers
  @proxy_connect_request_headers
end

Instance Method Details

#connect ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ruby_proxy_headers/net_http.rb', line 76

def connect
  return super unless use_ssl? && proxy?

  # Reject smuggled targets and header values before any socket I/O.
  RubyProxyHeaders.validate_connect_target!(conn_address, @port)
  RubyProxyHeaders.validate_connect_target!(@address, @port)
  proxy_connect_request_headers&.each do |key, value|
    RubyProxyHeaders.validate_header!(key, value)
  end

  @last_proxy_connect_response_headers = nil
  previous_http = Thread.current[:ruby_proxy_headers_active_http]
  previous_headers = Thread.current[:ruby_proxy_headers_connect_headers]
  begin
    Thread.current[:ruby_proxy_headers_active_http] = self
    Thread.current[:ruby_proxy_headers_connect_headers] = nil
    super
  ensure
    Thread.current[:ruby_proxy_headers_active_http] = previous_http
    if Thread.current[:ruby_proxy_headers_connect_headers].nil?
      Thread.current[:ruby_proxy_headers_connect_headers] = previous_headers
    end
  end
end