new options

This commit is contained in:
Christian Mehlmauer
2016-07-21 21:27:21 +02:00
parent 2cc5bb0311
commit 7f2762eb6f
3 changed files with 30 additions and 6 deletions

View File

@@ -18,7 +18,9 @@ class Browser
:request_timeout,
:connect_timeout,
:cookie,
:throttle
:throttle,
:disable_accept_header,
:disable_referer
]
@@instance = nil
@@ -68,6 +70,7 @@ class Browser
end
# Override for setting the User-Agent
# @param [ String ] user_agent
def user_agent=(user_agent)
Typhoeus::Config.user_agent = user_agent
end
@@ -158,6 +161,8 @@ class Browser
params.merge!(cookiejar: @cache_dir + '/cookie-jar')
params.merge!(cookiefile: @cache_dir + '/cookie-jar')
params.merge!(cookie: @cookie) if @cookie
params = Browser.remove_params_header_field(params, 'Accept') if @disable_accept_header
params = Browser.remove_params_header_field(params, 'Referer') if @disable_referer
params
end
@@ -177,4 +182,18 @@ class Browser
end
params
end
# @param [ Hash ] params
# @param [ String ] field
# @param [ Mixed ] field_value
#
# @return [ Array ]
def self.remove_params_header_field(params = {}, field)
if !params.has_key?(:headers)
params = params.merge(:headers => { field => nil })
elsif !params[:headers].has_key?(field)
params[:headers][field] = nil
end
params
end
end

View File

@@ -3,9 +3,8 @@
class Browser
module Options
attr_accessor :request_timeout, :connect_timeout
attr_accessor :request_timeout, :connect_timeout, :user_agent, :disable_accept_header, :disable_referer
attr_reader :basic_auth, :cache_ttl, :proxy, :proxy_auth, :throttle
attr_writer :user_agent
# Sets the Basic Authentification credentials
# Accepted format: