pebblebed 0.3.22 → 0.3.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pebblebed/http.rb +20 -13
- data/lib/pebblebed/version.rb +1 -1
- data/spec/http_spec.rb +25 -0
- data/spec/mock_pebble.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08c5433c73871b5f51b25a26056ce1fd53728451
|
4
|
+
data.tar.gz: b0f9a69395146a1809d9c0384a1de420cc797f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82ce8666be3e634e26e0bec2e07e88d56feca7603bae7029adb782b57c1b6d4ef534a391d81dfd62ba42f400b6d199f2ac9d25e89b1e26d4adc562f9fcaabdd6
|
7
|
+
data.tar.gz: 29c042e7f0466976ae79e15401d617e909b7b08da5578283fd9187cefe131417a1b89d4739ef5abbb2f1cb209846463d3d9177976bb141991b3172fcf377f89f
|
data/lib/pebblebed/http.rb
CHANGED
@@ -9,6 +9,7 @@ require 'pathbuilder'
|
|
9
9
|
require 'active_support'
|
10
10
|
|
11
11
|
module Pebblebed
|
12
|
+
|
12
13
|
class HttpError < StandardError
|
13
14
|
attr_reader :status, :message, :response
|
14
15
|
|
@@ -31,12 +32,18 @@ module Pebblebed
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
class HttpNotFoundError < HttpError
|
35
|
-
|
36
|
-
end
|
35
|
+
class HttpNotFoundError < HttpError; end
|
37
36
|
|
38
37
|
module Http
|
39
38
|
|
39
|
+
DEFAULT_CONNECT_TIMEOUT = 30
|
40
|
+
DEFAULT_REQUEST_TIMEOUT = nil
|
41
|
+
DEFAULT_READ_TIMEOUT = 30
|
42
|
+
|
43
|
+
class << self
|
44
|
+
attr_accessor :connect_timeout, :request_timeout, :read_timeout
|
45
|
+
end
|
46
|
+
|
40
47
|
class Response
|
41
48
|
def initialize(easy)
|
42
49
|
@body = easy.body_str
|
@@ -173,16 +180,16 @@ module Pebblebed
|
|
173
180
|
end
|
174
181
|
|
175
182
|
def self.with_easy(&block)
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
183
|
+
yield new_easy
|
184
|
+
end
|
185
|
+
|
186
|
+
def self.new_easy
|
187
|
+
easy = Curl::Easy.new
|
188
|
+
easy.connect_timeout = connect_timeout || DEFAULT_CONNECT_TIMEOUT
|
189
|
+
easy.timeout = request_timeout || DEFAULT_REQUEST_TIMEOUT
|
190
|
+
easy.low_speed_time = read_timeout || DEFAULT_READ_TIMEOUT
|
191
|
+
easy.low_speed_limit = 1
|
192
|
+
easy
|
186
193
|
end
|
187
194
|
|
188
195
|
def self.url_with_params(url, params)
|
data/lib/pebblebed/version.rb
CHANGED
data/spec/http_spec.rb
CHANGED
@@ -21,6 +21,10 @@ describe Pebblebed::Http do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
before :all do
|
24
|
+
Pebblebed::Http.connect_timeout = nil
|
25
|
+
Pebblebed::Http.request_timeout = nil
|
26
|
+
Pebblebed::Http.read_timeout = nil
|
27
|
+
|
24
28
|
# Starts the mock pebble at localhost:8666/api/mock/v1
|
25
29
|
mock_pebble.start
|
26
30
|
end
|
@@ -102,4 +106,25 @@ describe Pebblebed::Http do
|
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
109
|
+
it "enforces request timeout" do
|
110
|
+
Pebblebed::Http.request_timeout = 1
|
111
|
+
expect {
|
112
|
+
Pebblebed::Http.get(pebble_url, {slow: '2'})
|
113
|
+
}.to raise_error(Curl::Err::TimeoutError)
|
114
|
+
expect {
|
115
|
+
Pebblebed::Http.get(pebble_url, {slow: '0.5'})
|
116
|
+
}.not_to raise_error
|
117
|
+
end
|
118
|
+
|
119
|
+
it "enforces read timeout" do
|
120
|
+
Pebblebed::Http.request_timeout = 1000
|
121
|
+
Pebblebed::Http.read_timeout = 1
|
122
|
+
expect {
|
123
|
+
Pebblebed::Http.get(pebble_url, {slow: '30'})
|
124
|
+
}.to raise_error(Curl::Err::TimeoutError)
|
125
|
+
expect {
|
126
|
+
Pebblebed::Http.get(pebble_url, {slow: '0.5'})
|
127
|
+
}.not_to raise_error
|
128
|
+
end
|
129
|
+
|
105
130
|
end
|
data/spec/mock_pebble.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebblebed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katrina Owen
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-10-
|
12
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|