Skip to content

Commit 68debbc

Browse files
committed
Net::HTTP::Proxy returns Net::HTTP if proxy_host is nil
1 parent ad163ff commit 68debbc

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lib/resque/failure/hoptoad.rb

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'net/http'
21
require 'net/https'
32
require 'builder'
43
require 'uri'
@@ -12,15 +11,15 @@ module Failure
1211
# Resque::Failure::Hoptoad.configure do |config|
1312
# config.api_key = 'blah'
1413
# config.secure = true
15-
#
14+
#
1615
# # optional proxy support
1716
# config.proxy_host = 'x.y.z.t'
1817
# config.proxy_port = 8080
1918
# end
2019
class Hoptoad < Base
21-
#from the hoptoad plugin
22-
INPUT_FORMAT = %r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze
23-
20+
# From the hoptoad plugin
21+
INPUT_FORMAT = /^([^:]+):(\d+)(?::in `([^']+)')?$/
22+
2423
class << self
2524
attr_accessor :secure, :api_key, :proxy_host, :proxy_port
2625
end
@@ -36,14 +35,11 @@ def self.configure
3635
Resque::Failure.backend = self
3736
end
3837

39-
def request
40-
use_proxy? ? Net::HTTP::Proxy(self.class.proxy_host, self.class.proxy_port) : Net::HTTP
41-
end
42-
4338
def save
4439
http = use_ssl? ? :https : :http
4540
url = URI.parse("#{http}://hoptoadapp.com/notifier_api/v2/notices")
4641

42+
request = Net::HTTP::Proxy(self.class.proxy_host, self.class.proxy_port)
4743
http = request.new(url.host, url.port)
4844
headers = {
4945
'Content-type' => 'text/xml',
@@ -52,9 +48,9 @@ def save
5248

5349
http.read_timeout = 5 # seconds
5450
http.open_timeout = 2 # seconds
55-
51+
5652
http.use_ssl = use_ssl?
57-
53+
5854
begin
5955
response = http.post(url.path, xml, headers)
6056
rescue TimeoutError => e
@@ -69,7 +65,7 @@ def save
6965
log "Hoptoad Failure: #{response.class}\n#{body}"
7066
end
7167
end
72-
68+
7369
def xml
7470
x = Builder::XmlMarkup.new
7571
x.instruct!
@@ -102,21 +98,17 @@ def xml
10298
x.tag!("server-environment") do
10399
x.tag!("environment-name",RAILS_ENV)
104100
end
105-
101+
106102
end
107103
end
108-
104+
109105
def fill_in_backtrace_lines(x)
110106
exception.backtrace.each do |unparsed_line|
111107
_, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a
112108
x.line :file=>file,:number=>number
113109
end
114110
end
115111

116-
def use_proxy?
117-
self.class.proxy_host
118-
end
119-
120112
def use_ssl?
121113
self.class.secure
122114
end

0 commit comments

Comments
 (0)