Class: ChkDFront::Request

Inherits:
Object
  • Object
show all
Includes:
Providers
Defined in:
lib/chkdfront/request.rb

Overview

Contains all HTTP request related functionalities

Instance Attribute Summary collapse

Instance Method Summary collapse

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_frontObject (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_targetObject (readonly)

Returns the value of attribute front_target.



8
9
10
# File 'lib/chkdfront/request.rb', line 8

def front_target
  @front_target
end

#proxyObject (readonly)

Returns the value of attribute proxy.



14
15
16
# File 'lib/chkdfront/request.rb', line 14

def proxy
  @proxy
end

#requestNet::HTTP::Response (readonly)

Returns:

  • (Net::HTTP::Response)


20
21
22
# File 'lib/chkdfront/request.rb', line 20

def request
  @request
end

#res_errObject (readonly)

Returns the value of attribute res_err.



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

def res_err
  @res_err
end

#responseObject (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_outputObject



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

Parameters:

  • provider_name (Symbol)

    Available providers symbols:

    - :amazon
    - :azure
    - :alibaba
    
  • http_method (String) (defaults to: 'get')

Returns:

  • (Object)


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.message
rescue Net::ReadTimeout => e
  puts "#{self.class}##{__method__}:".error
  puts e.message
  puts "Remote port is closed.".error
  exit!
rescue Exception => e
  puts "#{self.class}##{__method__}:".error
  puts e.full_message
end