Class: ChkDFront::Request
- Inherits:
-
Object
- Object
- ChkDFront::Request
- Includes:
- Providers
- Defined in:
- lib/chkdfront/request.rb
Overview
Contains all HTTP request related functionalities
Instance Attribute Summary collapse
-
#domain_front ⇒ Object
readonly
Returns the value of attribute domain_front.
-
#front_target ⇒ Object
readonly
Returns the value of attribute front_target.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
- #request ⇒ Net::HTTP::Response readonly
-
#res_err ⇒ Object
readonly
Returns the value of attribute res_err.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #debug_output ⇒ Object
-
#initialize(front_target, domain_front, proxy) ⇒ Request
constructor
A new instance of Request.
-
#send_to(provider_name, http_method = 'get') ⇒ Object
Send GET/POST request to the targeted domain.
Methods included from Providers
#alibaba, #amazon, #azure, #get_provider
Constructor Details
#initialize(front_target, domain_front, proxy) ⇒ Request
Returns a new instance of Request.
28 29 30 31 32 33 |
# File 'lib/chkdfront/request.rb', line 28 def initialize(front_target, domain_front, proxy) @front_target = format_front_target(front_target) @domain_front = format_domain_front(domain_front) @proxy = format_proxy(proxy) @http = setup_http end |
Instance Attribute Details
#domain_front ⇒ Object (readonly)
Returns the value of attribute domain_front.
11 12 13 |
# File 'lib/chkdfront/request.rb', line 11 def domain_front @domain_front end |
#front_target ⇒ Object (readonly)
Returns the value of attribute front_target.
8 9 10 |
# File 'lib/chkdfront/request.rb', line 8 def front_target @front_target end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
14 15 16 |
# File 'lib/chkdfront/request.rb', line 14 def proxy @proxy end |
#request ⇒ Net::HTTP::Response (readonly)
20 21 22 |
# File 'lib/chkdfront/request.rb', line 20 def request @request end |
#res_err ⇒ Object (readonly)
Returns the value of attribute res_err.
26 27 28 |
# File 'lib/chkdfront/request.rb', line 26 def res_err @res_err end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
23 24 25 |
# File 'lib/chkdfront/request.rb', line 23 def response @response end |
Instance Method Details
#debug_output ⇒ Object
17 18 19 |
# File 'lib/chkdfront/request.rb', line 17 def debug_output @debug_output end |
#send_to(provider_name, http_method = 'get') ⇒ Object
Send GET/POST request to the targeted domain
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/chkdfront/request.rb', line 44 def send_to(provider_name, http_method='get') provider = get_provider(provider_name, @domain_front) @request = Net::HTTP.const_get(http_method.capitalize).new( @front_target.request_uri, provider[:headers] ) @response = @http.request(@request) check_http(@response) # if response failed, give the user some suggestion rescue SocketError => e puts "#{self.class}##{__method__}:".error puts e. rescue Net::ReadTimeout => e puts "#{self.class}##{__method__}:".error puts e. puts "Remote port is closed.".error exit! rescue Exception => e puts "#{self.class}##{__method__}:".error puts e. end |