http 0.8.0 → 0.8.1
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.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/lib/http/chainable.rb +34 -4
- data/lib/http/client.rb +11 -5
- data/lib/http/timeout/per_operation.rb +3 -1
- data/lib/http/version.rb +1 -1
- data/spec/lib/http_spec.rb +23 -0
- 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: a1b547d3276525790693e859ac473904b061f64b
|
4
|
+
data.tar.gz: e00cd095b96cd623c7e57a76c0203cf0c6f36854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01c71cc5f4123f61b30ba0152def5c55e694846813d0a007f0db30c42e83671a078459e048e84eeef80df5c5d3e930bd8afe6d20dd3822227c145fe03efa004e
|
7
|
+
data.tar.gz: 2ba200f4d59a4ff5b1f6ad1ea5412b100ed8599a926b4657c970e046439679a0506341372c7ba92eb6a3d18b0f38c9c90bef99e2de7bf071fdd749b6a3a6b086
|
data/CHANGES.md
CHANGED
data/lib/http/chainable.rb
CHANGED
@@ -72,11 +72,41 @@ module HTTP
|
|
72
72
|
branch(options).request verb, uri
|
73
73
|
end
|
74
74
|
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
75
|
+
# @overload persistent(host)
|
76
|
+
# Flags as persistent
|
77
|
+
# @param [String] host
|
78
|
+
# @raise [Request::Error] if Host is invalid
|
79
|
+
# @return [HTTP::Client] Persistent client
|
80
|
+
# @overload persistent(host, &block)
|
81
|
+
# Executes given block with persistent client and automatically closes
|
82
|
+
# connection at the end of execution.
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
#
|
86
|
+
# def keys(users)
|
87
|
+
# HTTP.persistent("https://github.com") do |http|
|
88
|
+
# users.map { |u| http.get("/#{u}.keys").to_s }
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# # same as
|
93
|
+
#
|
94
|
+
# def keys(users)
|
95
|
+
# http = HTTP.persistent "https://github.com"
|
96
|
+
# users.map { |u| http.get("/#{u}.keys").to_s }
|
97
|
+
# ensure
|
98
|
+
# http.close if http
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
#
|
102
|
+
# @yieldparam [HTTP::Client] client Persistent client
|
103
|
+
# @return [Object] result of last expression in the block
|
78
104
|
def persistent(host)
|
79
|
-
branch default_options.with_persistent host
|
105
|
+
p_client = branch default_options.with_persistent host
|
106
|
+
return p_client unless block_given?
|
107
|
+
yield p_client
|
108
|
+
ensure
|
109
|
+
p_client.close
|
80
110
|
end
|
81
111
|
|
82
112
|
# Make a request through an HTTP proxy
|
data/lib/http/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
1
3
|
require "cgi"
|
2
4
|
require "uri"
|
3
5
|
|
@@ -10,6 +12,7 @@ require "http/uri"
|
|
10
12
|
module HTTP
|
11
13
|
# Clients make requests and receive responses
|
12
14
|
class Client
|
15
|
+
extend Forwardable
|
13
16
|
include Chainable
|
14
17
|
|
15
18
|
CONNECTION = "Connection".freeze
|
@@ -58,6 +61,11 @@ module HTTP
|
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
64
|
+
# @!method persistent?
|
65
|
+
# @see Options#persistent?
|
66
|
+
# @return [Boolean] whenever client is persistent
|
67
|
+
def_delegator :default_options, :persistent?
|
68
|
+
|
61
69
|
def make_request(req, options)
|
62
70
|
verify_connection!(req.uri)
|
63
71
|
|
@@ -79,12 +87,10 @@ module HTTP
|
|
79
87
|
@state = :clean
|
80
88
|
|
81
89
|
res
|
82
|
-
|
83
|
-
# On any exception we reset the conn. This is a safety measure, to ensure
|
84
|
-
# we don't have conns in a bad state resulting in mixed requests/responses
|
85
90
|
rescue
|
86
|
-
|
87
|
-
|
91
|
+
# On any exception we reset the conn. This is a safety measure, to ensure
|
92
|
+
# we don't have conns in a bad state resulting in mixed requests/responses
|
93
|
+
close if persistent?
|
88
94
|
raise
|
89
95
|
end
|
90
96
|
|
data/lib/http/version.rb
CHANGED
data/spec/lib/http_spec.rb
CHANGED
@@ -163,4 +163,27 @@ RSpec.describe HTTP do
|
|
163
163
|
expect(client.default_options[:cache]).to eq cache
|
164
164
|
end
|
165
165
|
end
|
166
|
+
|
167
|
+
describe ".persistent" do
|
168
|
+
let(:host) { "https://api.github.com" }
|
169
|
+
|
170
|
+
context "with host only given" do
|
171
|
+
subject { HTTP.persistent host }
|
172
|
+
it { is_expected.to be_an HTTP::Client }
|
173
|
+
it { is_expected.to be_persistent }
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with host and block given" do
|
177
|
+
it "returns last evaluation of last expression" do
|
178
|
+
expect(HTTP.persistent(host) { :http }).to be :http
|
179
|
+
end
|
180
|
+
|
181
|
+
it "auto-closes connection" do
|
182
|
+
HTTP.persistent host do |client|
|
183
|
+
expect(client).to receive(:close).and_call_original
|
184
|
+
client.get("/repos/httprb/http.rb")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
166
189
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-04-
|
13
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: http_parser.rb
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.4.5
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: HTTP should be easy
|