http-client 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +13 -0
- data/lib/http/client.rb +24 -2
- data/test/test_request.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 442016d7995b5d8e1e31886a4aaff8a34102635d
|
4
|
+
data.tar.gz: f7bc4ab873d2cc41abccecac5b4d46c148e88d78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9347691549ccb5381f277597a198fd6042b3cfa3c6b3b0eafcf0f539cfd3ca7be6a6d5d7f36590d46099cbd98602757ff936754c0e3a3986dfe45085da216ca1
|
7
|
+
data.tar.gz: dfe32ba2b0e52035fe0572023fc34a914cc6b518cd00b746cd8779f895fa718b771094c37a51b29dd2ba0f268a6662090af82d4aaa0586b3c9634e65006e9523
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -45,6 +45,19 @@ HTTP::Client::Response
|
|
45
45
|
#last_effective_uri
|
46
46
|
```
|
47
47
|
|
48
|
+
### Exceptions
|
49
|
+
|
50
|
+
HTTP::Client rescues most Net::HTTP, Zlib and URI related exceptions and re-raises them as an appropriate exception.
|
51
|
+
You can retrieve the original exception using the `HTTP::Client::Error#original_error` instance method.
|
52
|
+
|
53
|
+
```
|
54
|
+
HTTP::Client::Error
|
55
|
+
HTTP::Client::Error::URI
|
56
|
+
HTTP::Client::Error::Zlib
|
57
|
+
HTTP::Client::Error::Timeout
|
58
|
+
HTTP::Client::Error::Transport
|
59
|
+
```
|
60
|
+
|
48
61
|
### Request parameters
|
49
62
|
|
50
63
|
#### Required
|
data/lib/http/client.rb
CHANGED
@@ -9,7 +9,7 @@ require 'zlib'
|
|
9
9
|
|
10
10
|
module HTTP
|
11
11
|
module Client
|
12
|
-
VERSION = '0.
|
12
|
+
VERSION = '0.3.0'
|
13
13
|
|
14
14
|
GET = Net::HTTP::Get
|
15
15
|
HEAD = Net::HTTP::Head
|
@@ -201,7 +201,7 @@ module HTTP
|
|
201
201
|
end
|
202
202
|
|
203
203
|
def request! uri, delegate
|
204
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
204
|
+
http = Net::HTTP.new(uri.host, uri.port, :ENV)
|
205
205
|
if uri.scheme == 'https'
|
206
206
|
http.use_ssl = true
|
207
207
|
http.verify_mode = @ssl_verify
|
@@ -214,6 +214,14 @@ module HTTP
|
|
214
214
|
response = http.request(delegate)
|
215
215
|
http.finish if http.started?
|
216
216
|
response
|
217
|
+
rescue URI::Error => e
|
218
|
+
raise Error::URI.new(e.message, e)
|
219
|
+
rescue Zlib::Error => e
|
220
|
+
raise Error::Zlib.new(e.message, e)
|
221
|
+
rescue Timeout::Error => e
|
222
|
+
raise Error::Timeout.new(e.message, e)
|
223
|
+
rescue Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
224
|
+
raise Error::Transport.new(e.message, e)
|
217
225
|
end
|
218
226
|
|
219
227
|
def redirect_to uri, code
|
@@ -418,5 +426,19 @@ module HTTP
|
|
418
426
|
#
|
419
427
|
def trace uri, args = {}; Request.new(TRACE, uri, args).execute; end
|
420
428
|
end
|
429
|
+
|
430
|
+
class Error < StandardError
|
431
|
+
attr_reader :original_error
|
432
|
+
|
433
|
+
def initialize message, original_error = nil
|
434
|
+
@original_error = original_error
|
435
|
+
super(message)
|
436
|
+
end
|
437
|
+
|
438
|
+
class URI < Error; end
|
439
|
+
class Zlib < Error; end
|
440
|
+
class Timeout < Error; end
|
441
|
+
class Transport < Error; end
|
442
|
+
end # Error
|
421
443
|
end # Client
|
422
444
|
end # HTTP
|
data/test/test_request.rb
CHANGED
@@ -47,7 +47,7 @@ describe 'HTTP Client Request' do
|
|
47
47
|
app = proc {|req| sleep }
|
48
48
|
server = TestServer.new(app)
|
49
49
|
server.run
|
50
|
-
assert_raises(
|
50
|
+
assert_raises(HTTP::Client::Error::Timeout) {HTTP::Client.get(server.root, timeout: 0.2)}
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'handles redirects' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bharanee Rathna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.6.8
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: A client wrapper around Net::HTTP
|