webmock 1.17.1 → 1.17.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +14 -1
- data/lib/webmock/http_lib_adapters/http_gem_adapter.rb +1 -1
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +4 -0
- data/lib/webmock/version.rb +1 -1
- data/spec/acceptance/curb/curb_spec.rb +49 -0
- data/spec/acceptance/shared/callbacks.rb +5 -5
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +6 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.17.2
|
4
|
+
|
5
|
+
* Support for chunked responses in Curb
|
6
|
+
|
7
|
+
Thanks to [Zachary Belzer](https://github.com/zbelzer)
|
8
|
+
|
9
|
+
* Fixed handling of request body passed as a hash to `Typhoeus.post`
|
10
|
+
|
11
|
+
Thanks to [Mason Chang](https://github.com/changmason) for reporting.
|
12
|
+
|
3
13
|
## 1.17.1
|
4
14
|
|
5
15
|
* Added missing license statements.
|
@@ -125,6 +125,7 @@ if defined?(Curl)
|
|
125
125
|
end
|
126
126
|
|
127
127
|
@content_type = webmock_response.headers["Content-Type"]
|
128
|
+
@transfer_encoding = webmock_response.headers["Transfer-Encoding"]
|
128
129
|
end
|
129
130
|
|
130
131
|
@last_effective_url ||= self.url
|
@@ -144,7 +145,15 @@ if defined?(Curl)
|
|
144
145
|
def invoke_curb_callbacks
|
145
146
|
@on_progress.call(0.0,1.0,0.0,1.0) if @on_progress
|
146
147
|
self.header_str.lines.each { |header_line| @on_header.call header_line } if @on_header
|
147
|
-
|
148
|
+
if @on_body
|
149
|
+
if chunked_response?
|
150
|
+
self.body_str.each do |chunk|
|
151
|
+
@on_body.call(chunk)
|
152
|
+
end
|
153
|
+
else
|
154
|
+
@on_body.call(self.body_str)
|
155
|
+
end
|
156
|
+
end
|
148
157
|
@on_complete.call(self) if @on_complete
|
149
158
|
|
150
159
|
case response_code
|
@@ -155,6 +164,10 @@ if defined?(Curl)
|
|
155
164
|
end
|
156
165
|
end
|
157
166
|
|
167
|
+
def chunked_response?
|
168
|
+
@transfer_encoding == 'chunked' && self.body_str.respond_to?(:each)
|
169
|
+
end
|
170
|
+
|
158
171
|
def build_webmock_response
|
159
172
|
status, headers =
|
160
173
|
WebMock::HttpLibAdapters::CurbAdapter.parse_header_string(self.header_str)
|
data/lib/webmock/version.rb
CHANGED
@@ -81,6 +81,20 @@ unless RUBY_PLATFORM =~ /java/
|
|
81
81
|
test.should == body
|
82
82
|
end
|
83
83
|
|
84
|
+
it "should call on_body for each chunk with chunked response" do
|
85
|
+
body = "on_body fired"
|
86
|
+
stub_request(:any, "example.com").
|
87
|
+
to_return(:body => ["first_chunk", "second_chunk"],
|
88
|
+
:headers => {"Transfer-Encoding" => "chunked"})
|
89
|
+
|
90
|
+
test = []
|
91
|
+
@curl.on_body do |data|
|
92
|
+
test << data
|
93
|
+
end
|
94
|
+
@curl.http_get
|
95
|
+
test.should == ["first_chunk", "second_chunk"]
|
96
|
+
end
|
97
|
+
|
84
98
|
it "should call on_header when response headers are read" do
|
85
99
|
stub_request(:any, "example.com").
|
86
100
|
to_return(:headers => {:one => 1})
|
@@ -267,6 +281,41 @@ unless RUBY_PLATFORM =~ /java/
|
|
267
281
|
end
|
268
282
|
end
|
269
283
|
end
|
284
|
+
|
285
|
+
describe "#chunked_response?" do
|
286
|
+
before(:each) do
|
287
|
+
@curl = Curl::Easy.new
|
288
|
+
@curl.url = "http://example.com"
|
289
|
+
end
|
290
|
+
|
291
|
+
it "is true when Transfer-Encoding is 'chunked' and body responds to each" do
|
292
|
+
stub_request(:any, 'example.com').
|
293
|
+
to_return(:body => ["abc", "def"],
|
294
|
+
:status => 200,
|
295
|
+
:headers => { 'Transfer-Encoding' => 'chunked' })
|
296
|
+
|
297
|
+
@curl.http_get
|
298
|
+
@curl.should be_chunked_response
|
299
|
+
end
|
300
|
+
|
301
|
+
it "is false when Transfer-Encoding is not 'chunked'" do
|
302
|
+
stub_request(:any, 'example.com').
|
303
|
+
to_return(:body => ["abc", "def"],
|
304
|
+
:status => 200)
|
305
|
+
|
306
|
+
@curl.http_get
|
307
|
+
@curl.should_not be_chunked_response
|
308
|
+
end
|
309
|
+
|
310
|
+
it "is false when Transfer-Encoding is 'chunked' but body does not respond to each" do
|
311
|
+
stub_request(:any, 'example.com').
|
312
|
+
to_return(:body => "abc",
|
313
|
+
:status => 200)
|
314
|
+
|
315
|
+
@curl.http_get
|
316
|
+
@curl.should_not be_chunked_response
|
317
|
+
end
|
318
|
+
end
|
270
319
|
end
|
271
320
|
|
272
321
|
describe "Webmock with Curb" do
|
@@ -101,20 +101,20 @@ shared_context "callbacks" do |*adapter_info|
|
|
101
101
|
WebMock.after_request(:except => [:other_lib]) do |_, response|
|
102
102
|
@response = response
|
103
103
|
end
|
104
|
-
http_request(:get, "http://httpstat.us/
|
104
|
+
http_request(:get, "http://httpstat.us/201")
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should pass real response to callback with status and message" do
|
108
|
-
@response.status[0].should ==
|
109
|
-
@response.status[1].should == "
|
108
|
+
@response.status[0].should == 201
|
109
|
+
@response.status[1].should == "Created" unless adapter_info.include?(:no_status_message)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should pass real response to callback with headers" do
|
113
|
-
@response.headers["Content-Length"].should == "
|
113
|
+
@response.headers["Content-Length"].should == "11"
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should pass response to callback with body" do
|
117
|
-
@response.body.size.should ==
|
117
|
+
@response.body.size.should == 11
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -28,6 +28,12 @@ unless RUBY_PLATFORM =~ /java/
|
|
28
28
|
hydra.run
|
29
29
|
end
|
30
30
|
|
31
|
+
it "should take into account body for POST request" do
|
32
|
+
stub_request(:post, "www.example.com").with(:body => {:hello => 'world'})
|
33
|
+
response = Typhoeus.post("http://www.example.com", :method => :post, :body => {:hello => 'world'})
|
34
|
+
expect(response.code).to eq(200)
|
35
|
+
end
|
36
|
+
|
31
37
|
it "should take into account params for GET request" do
|
32
38
|
stub_request(:get, "http://www.example.com/?hello=world").to_return({})
|
33
39
|
request = Typhoeus::Request.new("http://www.example.com/?hello=world", :method => :get)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 87
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 17
|
9
|
-
-
|
10
|
-
version: 1.17.
|
9
|
+
- 2
|
10
|
+
version: 1.17.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bartosz Blimke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2014-
|
18
|
+
date: 2014-02-02 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|