Module: RubyProxyHeaders::Typhoeus
- Defined in:
- lib/ruby_proxy_headers/typhoeus.rb
Overview
Typhoeus/Ethon integration for proxy headers support. Typhoeus wraps libcurl, which has native support for CURLOPT_PROXYHEADER.
Defined Under Namespace
Classes: ProxyResponse
Class Method Summary collapse
-
.get(url, proxy:, proxy_headers: {}, **options) ⇒ ProxyResponse
Make a GET request with proxy headers.
-
.post(url, proxy:, proxy_headers: {}, body: nil, **options) ⇒ Object
Make a POST request with proxy headers.
-
.request(method, url, proxy:, proxy_headers: {}, **options) ⇒ ProxyResponse
Make a request with proxy headers.
Class Method Details
.get(url, proxy:, proxy_headers: {}, **options) ⇒ ProxyResponse
Make a GET request with proxy headers.
22 23 24 |
# File 'lib/ruby_proxy_headers/typhoeus.rb', line 22 def self.get(url, proxy:, proxy_headers: {}, **) request(:get, url, proxy: proxy, proxy_headers: proxy_headers, **) end |
.post(url, proxy:, proxy_headers: {}, body: nil, **options) ⇒ Object
Make a POST request with proxy headers.
27 28 29 |
# File 'lib/ruby_proxy_headers/typhoeus.rb', line 27 def self.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) ⇒ ProxyResponse
Make a request with proxy headers.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_proxy_headers/typhoeus.rb', line 38 def self.request(method, url, proxy:, proxy_headers: {}, **) require 'typhoeus' uri = URI.parse(url) # For HTTPS, we need custom handling since Typhoeus doesn't expose CURLOPT_PROXYHEADER if uri.scheme == 'https' && !proxy_headers.empty? # Use our core connection for now # TODO: Extend Ethon to expose CURLOPT_PROXYHEADER for native support response = RubyProxyHeaders::NetHTTP.request( method, url, proxy: proxy, proxy_headers: proxy_headers, headers: [:headers], body: [:body] ) return response end # For HTTP or no proxy headers, use standard Typhoeus = .merge( proxy: proxy, method: method ) response = ::Typhoeus::Request.new(url, ).run ProxyResponse.new(response, {}) end |