webtester 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/request.rb +23 -26
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4036ca95e2545491eacb48d4b40cb7568a5beaa6
4
- data.tar.gz: 69d5486c71465bbb9c254fbecdd2882d3fc15751
3
+ metadata.gz: 429bb7365ea2e47cfb103859a61de99e9ec466ab
4
+ data.tar.gz: 1e66cd581083a9611809501d2b5c44e581b08679
5
5
  SHA512:
6
- metadata.gz: fdf2c606e4ab77faa22387be896ea42f07e66cab71dd3c1e8597b0a6b8432fdda637a6a7a5a310ecb092532aff9100d676f9f21aa2638cffba237d0434e2d8b2
7
- data.tar.gz: 9cbbd6e86d668ef29d14e06e08c2896b6d96a9cb8652bedc25e8862fc26d39df8316d3ea59ae480a130d071acd7ddde56f7e18bbd930d538ae85979ae79e513e
6
+ metadata.gz: ed434569b32dc128d04e0251853a3f42927d114c3b8e3f847de28e021551022fda8f967f4a8bd1fa0e5f14be5dcefa3491ff1b2344b04f132ba6f06903a994bf
7
+ data.tar.gz: c4e02a17fd98b33303a4994e503f9869d7ed70b36523e2cb10b56e731987bb5d1c02d3112137c21b6e801164985afa6804570bda935102607f452730e3e76903
data/lib/request.rb CHANGED
@@ -46,8 +46,8 @@ module WT
46
46
  def get
47
47
  url = URI.parse @request_url
48
48
  url.path = '/' unless url.path.length > 0
49
-
50
- req = Net::HTTP::Get.new(url.to_s)
49
+
50
+ req = Net::HTTP::Get.new(url.path)
51
51
 
52
52
  self.request_protocol = url.scheme.downcase
53
53
 
@@ -58,7 +58,7 @@ module WT
58
58
  url = URI.parse @request_url
59
59
  url.path = '/' unless url.path.length > 0
60
60
 
61
- req = Net::HTTP::Post.new(url.to_s)
61
+ req = Net::HTTP::Post.new(url.path)
62
62
 
63
63
  self.request_protocol = url.scheme.downcase
64
64
 
@@ -69,20 +69,12 @@ module WT
69
69
 
70
70
  WT::Log.debug(">> WT::Request::send(host: #{host}, port: #{port})")
71
71
 
72
- host_ip = host;
73
-
74
- unless host.match(/^[0-9]{1,3}(\.[0-9]{1,3}){3}$/)
75
- WT::Log.debug("\t* resolving #{host}...")
76
-
72
+ unless host.match(/^[0-9]{1,3}(\.[0-9]{1,3}){3}$/) or self.proxy_host
77
73
  begin
78
- host_ip = Resolv::DNS.new().getaddress(host).to_s
74
+ Resolv::DNS.new().getaddress(host).to_s
79
75
  rescue Resolv::ResolvError => re
80
76
  raise DNSResolvErrorException.new(host)
81
77
  end
82
-
83
- WT::Log.debug("\t\t* success: #{host_ip}")
84
- else
85
- WT::Log.debug("\t * no need to resolv. Already in IP format.")
86
78
  end
87
79
 
88
80
  ret = nil
@@ -96,29 +88,34 @@ module WT
96
88
 
97
89
  req.body = request_body
98
90
 
99
- http = nil
91
+ response = nil
92
+ ssl = (self.request_protocol == 'https')
93
+ options = if ssl
94
+ { :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE }
95
+ else
96
+ {}
97
+ end
100
98
 
101
99
  if self.proxy_host
102
100
  WT::Log.debug("\t* @proxy_host = #{self.proxy_host}, proxy_port = #{self.proxy_port}")
103
- http = Net::HTTP.new(self.proxy_host, self.proxy_port)
101
+ Net::HTTP::Proxy(self.proxy_host, self.proxy_port).start(host, port, options) do |http|
102
+ WT::Log.debug("\t* http.request(#{host})")
103
+ response = http.request(req)
104
+ end
104
105
  else
105
- WT::Log.debug("\t* Net::HTTP.new(#{host_ip}, #{port})")
106
- http = Net::HTTP.new(host_ip, port)
107
- end
108
-
109
- if self.request_protocol == 'https'
110
- http.use_ssl = true
111
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE;
106
+ WT::Log.debug("\t* Net::HTTP.start(#{host}, #{port})")
107
+ Net::HTTP.start(host, port, options) do |http|
108
+ WT::Log.debug("\t* http.request(#{host})")
109
+ response = http.request(req)
110
+ end
112
111
  end
113
112
 
114
- WT::Log.debug("\t* http.request(request)")
115
- response = http.request(req)
116
-
117
- raise "Could not connect to host: #{host_ip}:#{port}" unless response
113
+ raise "Could not connect to host: #{host}:#{port}" unless response
118
114
 
119
115
  ret = WT::Result.new(self, response)
120
116
 
121
117
  WT::Log.debug("\t* WT::Result.new(self, response): #{response.code}")
118
+
122
119
  rescue Exception => e
123
120
  WT::Log.error("\t* Exception: #{e.message}")
124
121
  ret = WT::Result.new self, nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webtester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego F. Nascimento