http_streaming_client 0.9.3 → 0.9.4
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/CHANGELOG +6 -1
- data/README.md +1 -1
- data/lib/http_streaming_client/client.rb +45 -41
- data/lib/http_streaming_client/version.rb +1 -1
- data/spec/reconnect_spec.rb +5 -5
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80770e5181fa02ff14ec3ecb822a9a46ca6208fe
|
4
|
+
data.tar.gz: 4910d040593d3edac671776221161b2166c8d0ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc55d5c9795a03587c53192ddb0220880fffdae3a347a0dd5e20bace30315de426e2a8857638d6dd7fc33daf6e262fda96f03c7b276dc6deb79437f000a5eb1f
|
7
|
+
data.tar.gz: da081fe39235ef44906e5c334c2b1ad99b32b818a2320946b80cd3cbdc199037302b366f44f190ddbd9841c29834f5e0d0be6d55754cee1afdc3d694633efe5b
|
data/CHANGELOG
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
http_streaming_client 0.9.
|
1
|
+
http_streaming_client 0.9.4 (05.22.2014)
|
2
|
+
========================================
|
3
|
+
* Fixed bug with reconnect management and lazy authorization header generation
|
4
|
+
* Tested and updated for MRI ruby-2.1.1p76 and JRuby jruby-1.7.12
|
5
|
+
|
6
|
+
http_streaming_client 0.9.3 (05.09.2014)
|
2
7
|
========================================
|
3
8
|
* Critical bug fix for GZip chunked deceompression handling
|
4
9
|
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Ruby HTTP client with support for HTTP 1.1 streaming, GZIP and zlib compressed s
|
|
7
7
|
|
8
8
|
## Ruby Version
|
9
9
|
|
10
|
-
MRI
|
10
|
+
MRI 2.1.1p76 and JRuby jruby-1.7.12. Install via rvm: https://rvm.io/
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -124,52 +124,55 @@ module HttpStreamingClient
|
|
124
124
|
uri = URI.parse(uri)
|
125
125
|
end
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
logger.debug("Client::request:options_factory:#{generated_options}")
|
133
|
-
opts.merge!(generated_options || {})
|
134
|
-
else
|
135
|
-
logger.warn("Client::request:options_factory detected, but does not respond to get_options(). Ignoring.")
|
136
|
-
end
|
137
|
-
end
|
127
|
+
@reconnect_count = 0 if @reconnect_requested
|
128
|
+
@options_factory = opts.delete(:options_factory)
|
129
|
+
@static_body_option = opts[:body]
|
130
|
+
|
131
|
+
begin
|
138
132
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
133
|
+
opts[:body] = @static_body_option unless @static_body_option.nil?
|
134
|
+
|
135
|
+
if !@options_factory.nil? then
|
136
|
+
if @options_factory.respond_to? "get_options" then
|
137
|
+
logger.info("Client::request:options_factory detected")
|
138
|
+
generated_options = @options_factory.get_options
|
139
|
+
logger.info("Client::request:options_factory:#{generated_options}")
|
140
|
+
opts.merge!(generated_options || {})
|
141
|
+
else
|
142
|
+
logger.warn("Client::request:options_factory detected, but does not respond to get_options(). Ignoring.")
|
143
|
+
end
|
150
144
|
end
|
151
|
-
default_headers["Content-Length"] = body.length
|
152
|
-
end
|
153
145
|
|
154
|
-
|
155
|
-
|
156
|
-
|
146
|
+
default_headers = {
|
147
|
+
"User-Agent" => opts["User-Agent"] || "HttpStreamingClient #{HttpStreamingClient::VERSION}",
|
148
|
+
"Accept" => "*/*",
|
149
|
+
"Accept-Charset" => "utf-8"
|
150
|
+
}
|
151
|
+
|
152
|
+
if method == "POST" || method == "PUT"
|
153
|
+
default_headers["Content-Type"] = opts["Content-Type"] || "application/x-www-form-urlencoded;charset=UTF-8"
|
154
|
+
body = opts.delete(:body)
|
155
|
+
if body.is_a?(Hash)
|
156
|
+
body = body.keys.collect {|param| "#{URI.escape(param.to_s)}=#{URI.escape(body[param].to_s)}"}.join('&')
|
157
|
+
end
|
158
|
+
default_headers["Content-Length"] = body.length
|
159
|
+
end
|
157
160
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
default_headers["Accept-Encoding"] = "#{encodings.join(',')}"
|
162
|
-
end
|
161
|
+
unless uri.userinfo.nil?
|
162
|
+
default_headers["Authorization"] = "Basic #{[uri.userinfo].pack('m').strip!}\r\n"
|
163
|
+
end
|
163
164
|
|
164
|
-
|
165
|
-
|
165
|
+
encodings = []
|
166
|
+
encodings << "gzip" if (@compression_requested and opts[:compression].nil?) or opts[:compression]
|
167
|
+
if encodings.any?
|
168
|
+
default_headers["Accept-Encoding"] = "#{encodings.join(',')}"
|
169
|
+
end
|
166
170
|
|
167
|
-
|
171
|
+
headers = default_headers.merge(opts[:headers] || {})
|
172
|
+
logger.debug "request headers: #{headers}"
|
168
173
|
|
169
174
|
socket = initialize_socket(uri, opts)
|
170
175
|
|
171
|
-
@reconnect_count = 0 if @reconnect_requested
|
172
|
-
|
173
176
|
request = "#{method} #{uri.path}#{uri.query ? "?"+uri.query : nil} HTTP/1.1\r\n"
|
174
177
|
request << "Host: #{uri.host}\r\n"
|
175
178
|
headers.each do |k, v|
|
@@ -254,7 +257,7 @@ module HttpStreamingClient
|
|
254
257
|
logger.debug "read #{line.size} uncompressed bytes, #{response.size} bytes total, decoder queue bytes:#{decoder.size}"
|
255
258
|
response << line unless @interrupted }
|
256
259
|
end
|
257
|
-
|
260
|
+
else
|
258
261
|
logger.debug "chunked transfer encoding with no compression detected"
|
259
262
|
if block_given? then
|
260
263
|
decoder = HttpStreamingClient::Decoders::Chunked.new { |line|
|
@@ -295,8 +298,8 @@ module HttpStreamingClient
|
|
295
298
|
decoder << partial
|
296
299
|
|
297
300
|
if !block_given? then
|
298
|
-
|
299
|
-
|
301
|
+
logger.debug "no block specified, returning chunk results and halting streaming response"
|
302
|
+
return response
|
300
303
|
else
|
301
304
|
return if @interrupted and response_compression
|
302
305
|
return response if @interrupted
|
@@ -380,11 +383,12 @@ module HttpStreamingClient
|
|
380
383
|
if @reconnect_requested then
|
381
384
|
logger.info "Connection closed. Reconnect requested. Trying..."
|
382
385
|
@reconnect_count = @reconnect_count + 1
|
386
|
+
logger.info "@reconnect_count is #{@reconnect_count} of #{@reconnect_attempts}, sleeping for #{@reconnect_interval}..."
|
383
387
|
sleep @reconnect_interval
|
384
388
|
retry if @reconnect_count < @reconnect_attempts
|
385
389
|
logger.info "Maximum number of failed reconnect attempts reached (#{@reconnect_attempts}). Exiting."
|
386
390
|
end
|
387
|
-
|
391
|
+
|
388
392
|
raise e unless e.instance_of? ReconnectRequest
|
389
393
|
end
|
390
394
|
ensure
|
data/spec/reconnect_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe HttpStreamingClient do
|
|
10
10
|
|
11
11
|
count = 0
|
12
12
|
client = HttpStreamingClient::Client.new(compression: false)
|
13
|
-
response = client.get("http://localhost:3000/outbounds/consumer
|
13
|
+
response = client.get("http://localhost:3000/outbounds/consumer") { |line|
|
14
14
|
logger.debug "line received: #{line}"
|
15
15
|
count = count + 1
|
16
16
|
}
|
@@ -18,12 +18,12 @@ describe HttpStreamingClient do
|
|
18
18
|
expect(count).to be(10)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
it "should reconnect on any error or EOF", :disabled => true do
|
21
|
+
it "should reconnect on any error or EOF" do
|
22
|
+
#it "should reconnect on any error or EOF", :disabled => true do
|
23
23
|
|
24
|
-
client = HttpStreamingClient::Client.new(compression: false, reconnect: true, reconnect_attempts: 5, reconnect_interval:
|
24
|
+
client = HttpStreamingClient::Client.new(compression: false, reconnect: true, reconnect_attempts: 5, reconnect_interval: 5)
|
25
25
|
count = 0
|
26
|
-
response = client.get("http://localhost:3000/outbounds/consumer
|
26
|
+
response = client.get("http://localhost:3000/outbounds/consumer") { |line|
|
27
27
|
logger.debug "line received: #{line}"
|
28
28
|
count = count + 1
|
29
29
|
client.interrupt if count > 20
|
metadata
CHANGED
@@ -1,127 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_streaming_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Tompkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.1'
|
34
|
-
- -
|
34
|
+
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 10.1.1
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '10.1'
|
44
|
-
- -
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 10.1.1
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ~>
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '2.13'
|
54
|
-
- -
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 2.13.0
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - ~>
|
61
|
+
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '2.13'
|
64
|
-
- -
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: 2.13.0
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: simplecov
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - ~>
|
71
|
+
- - "~>"
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0.7'
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: 0.7.1
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - ~>
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0.7'
|
84
|
-
- -
|
84
|
+
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: 0.7.1
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: coveralls
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- - ~>
|
91
|
+
- - "~>"
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0.7'
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.7.0
|
97
97
|
type: :development
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0.7'
|
104
|
-
- -
|
104
|
+
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: 0.7.0
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
108
|
name: json
|
109
109
|
requirement: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- - ~>
|
111
|
+
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '1.8'
|
114
|
-
- -
|
114
|
+
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: 1.8.0
|
117
117
|
type: :runtime
|
118
118
|
prerelease: false
|
119
119
|
version_requirements: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- - ~>
|
121
|
+
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '1.8'
|
124
|
-
- -
|
124
|
+
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: 1.8.0
|
127
127
|
description: Ruby HTTP client with streaming support for GZIP compressed streams and
|
@@ -133,7 +133,7 @@ executables: []
|
|
133
133
|
extensions: []
|
134
134
|
extra_rdoc_files: []
|
135
135
|
files:
|
136
|
-
- .gitignore
|
136
|
+
- ".gitignore"
|
137
137
|
- AUTHORS
|
138
138
|
- CHANGELOG
|
139
139
|
- Gemfile
|
@@ -178,12 +178,12 @@ require_paths:
|
|
178
178
|
- lib
|
179
179
|
required_ruby_version: !ruby/object:Gem::Requirement
|
180
180
|
requirements:
|
181
|
-
- -
|
181
|
+
- - ">="
|
182
182
|
- !ruby/object:Gem::Version
|
183
183
|
version: '0'
|
184
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
185
|
requirements:
|
186
|
-
- -
|
186
|
+
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
188
|
version: '0'
|
189
189
|
requirements: []
|