Module: HTTP::Request::Proxy

Included in:
HTTP::Request
Defined in:
lib/http/request/proxy.rb

Overview

Proxy-related methods for HTTP requests

Instance Method Summary collapse

Instance Method Details

#connect_using_proxy(socket) ⇒ void

This method returns an undefined value.

Setup tunnel through proxy for SSL request

Examples:

request.connect_using_proxy(socket)


49
50
51
# File 'lib/http/request/proxy.rb', line 49

def connect_using_proxy(socket)
  Writer.new(socket, nil, proxy_connect_headers, proxy_connect_header).connect_through_proxy
end

#include_proxy_authorization_headervoid

This method returns an undefined value.

Compute and add the Proxy-Authorization header

Examples:

request.include_proxy_authorization_header


26
27
28
# File 'lib/http/request/proxy.rb', line 26

def include_proxy_authorization_header
  headers[Headers::PROXY_AUTHORIZATION] = proxy_authorization_header
end

#include_proxy_headersvoid

This method returns an undefined value.

Merges proxy headers into the request headers

Examples:

request.include_proxy_headers


14
15
16
17
# File 'lib/http/request/proxy.rb', line 14

def include_proxy_headers
  headers.merge!(proxy[:proxy_headers]) if proxy.key?(:proxy_headers)
  include_proxy_authorization_header if using_authenticated_proxy?
end

#proxy_authorization_headerString

Build the Proxy-Authorization header value

Examples:

request.proxy_authorization_header

Returns:

  • (String)


37
38
39
40
# File 'lib/http/request/proxy.rb', line 37

def proxy_authorization_header
  digest = encode64(format("%s:%s", proxy.fetch(:proxy_username), proxy.fetch(:proxy_password)))
  "Basic #{digest}"
end

#proxy_connect_headerString

Compute HTTP request header SSL proxy connection

Examples:

request.proxy_connect_header

Returns:

  • (String)


60
61
62
# File 'lib/http/request/proxy.rb', line 60

def proxy_connect_header
  "CONNECT #{host}:#{port} HTTP/#{version}"
end

#proxy_connect_headersHTTP::Headers

Headers to send with proxy connect request

Examples:

request.proxy_connect_headers

Returns:



71
72
73
74
75
76
77
78
79
80
# File 'lib/http/request/proxy.rb', line 71

def proxy_connect_headers
  connect_headers = Headers.coerce(
    Headers::HOST       => headers[Headers::HOST],
    Headers::USER_AGENT => headers[Headers::USER_AGENT]
  )

  connect_headers[Headers::PROXY_AUTHORIZATION] = proxy_authorization_header if using_authenticated_proxy?
  connect_headers.merge!(proxy[:proxy_headers]) if proxy.key?(:proxy_headers)
  connect_headers
end