Module: RubyProxyHeaders::Typhoeus
- Defined in:
- lib/ruby_proxy_headers/typhoeus.rb
Overview
Typhoeus adapter using libcurl's proxy-header list.
Typhoeus 1.7 / Ethon 0.19 expose :proxyheader (CURLOPT_PROXYHEADER) and
:headeropt (CURLOPT_HEADEROPT). With headeropt: :separate, those
headers are sent only to the proxy. On HTTPS that is the CONNECT request.
:headers stay on the tunneled origin request.
libcurl records the CONNECT response as the first header block of
response_headers and the origin response after it. Typhoeus's
response.headers is only the last block. On HTTPS through a proxy,
proxy_response_headers is that first block when its status is 2xx.
Defined Under Namespace
Classes: ProxyResponse
Constant Summary collapse
- HTTP_STATUS =
%r{\AHTTP/\d+(?:\.\d+)?\s+(\d{3})\b}i
Class Method Summary collapse
- .get(url, proxy:, proxy_headers: {}, **options) ⇒ Object
- .post(url, proxy:, proxy_headers: {}, body: nil, **options) ⇒ Object
- .request(method, url, proxy:, proxy_headers: {}, **options) ⇒ Object
Class Method Details
.get(url, proxy:, proxy_headers: {}, **options) ⇒ Object
37 38 39 |
# File 'lib/ruby_proxy_headers/typhoeus.rb', line 37 def get(url, proxy:, proxy_headers: {}, **) request(:get, url, proxy: proxy, proxy_headers: proxy_headers, **) end |
.post(url, proxy:, proxy_headers: {}, body: nil, **options) ⇒ Object
41 42 43 |
# File 'lib/ruby_proxy_headers/typhoeus.rb', line 41 def post(url, proxy:, proxy_headers: {}, body: nil, **) request(:post, url, proxy: proxy, proxy_headers: proxy_headers, body: body, **) end |
.request(method, url, proxy:, proxy_headers: {}, **options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_proxy_headers/typhoeus.rb', line 45 def request(method, url, proxy:, proxy_headers: {}, **) = .merge(proxy: proxy, method: method) unless proxy_headers.empty? lines = proxy_headers.map do |name, value| RubyProxyHeaders.validate_header!(name, value) "#{name}: #{value}" end # The Slist has to stay in the options Typhoeus keeps. libcurl does not # copy CURLOPT_PROXYHEADER, and Ethon clears its own reference on reset. [:proxyheader] = ::Ethon::Curl::Slist.new(::Ethon::Curl::Slist.build(lines)) [:headeropt] = :separate end response = ::Typhoeus::Request.new(url, ).run ProxyResponse.new(response, connect_headers(response, url, proxy)) end |