http 4.3.0 → 4.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 442e2d5e2fd1d2ba92254a616a5856d500aafbadd3c7d2f55f5b0d36528b10dd
4
- data.tar.gz: 50191bc30051029cd1ece0a04322e8fd772176320377356a1e79404e2ceb90fd
3
+ metadata.gz: c303ff626f5b57ed080d5d64d3ba7fd0a9eed5bc9463ff1035b1386dad36a9ab
4
+ data.tar.gz: 3bc824e2ab723de39556166ec821d8c9a3f14dc5bc8dd542e4ccadf916a2518a
5
5
  SHA512:
6
- metadata.gz: 40cb047577f2b50864039116e1fddd72b5290bdb494649498a4fbe6ec3a4d40c875ab42f4387692842aa820798fec200f8fb90a717fc58c9113929ce5780affc
7
- data.tar.gz: dfc32cfa989b1007cb9085973ea61ab3b681d42dfa5c150662d80f97d972a0de583d0eb0d1673cfb9aee91743e97f619c63f75593b3c9288a5621742845b04fb
6
+ metadata.gz: 9e78a6c25816e48f36394d3e4d612d94b47eb45787ca74a1fd5f49372c3df1037e535a401392a3318bfcc7194a1afee361794aadab853ae420054f00015101d0
7
+ data.tar.gz: 9e1656f514777d0c5c149b273d9276b3c2affb93363c3cbc74a20c1a7fed039148564adad891459eac012415d4d1dee98238bcf3e6a0f3e978fa4263afa4925b
data/CHANGES.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 4.4.0 (2020-03-25)
2
+
3
+ * Backport [#587](https://github.com/httprb/http/pull/587)
4
+ Fix redirections when server responds with multiple Location headers.
5
+ ([@ixti])
6
+
7
+ * Backport [#599](https://github.com/httprb/http/pull/599)
8
+ Allow passing HTTP::FormData::{Multipart,UrlEncoded} object directly.
9
+ ([@ixti])
10
+
1
11
  ## 4.3.0 (2020-01-09)
2
12
 
3
13
  * Backport [#581](https://github.com/httprb/http/pull/581)
@@ -169,7 +169,7 @@ module HTTP
169
169
  when opts.body
170
170
  opts.body
171
171
  when opts.form
172
- form = HTTP::FormData.create opts.form
172
+ form = make_form_data(opts.form)
173
173
  headers[Headers::CONTENT_TYPE] ||= form.content_type
174
174
  form
175
175
  when opts.json
@@ -178,5 +178,12 @@ module HTTP
178
178
  body
179
179
  end
180
180
  end
181
+
182
+ def make_form_data(form)
183
+ return form if form.is_a? HTTP::FormData::Multipart
184
+ return form if form.is_a? HTTP::FormData::Urlencoded
185
+
186
+ HTTP::FormData.create(form)
187
+ end
181
188
  end
182
189
  end
@@ -58,7 +58,8 @@ module HTTP
58
58
 
59
59
  @response.flush
60
60
 
61
- @request = redirect_to @response.headers[Headers::LOCATION]
61
+ # XXX(ixti): using `Array#inject` to return `nil` if no Location header.
62
+ @request = redirect_to(@response.headers.get(Headers::LOCATION).inject(:+))
62
63
  @response = yield @request
63
64
  end
64
65
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTP
4
- VERSION = "4.3.0"
4
+ VERSION = "4.4.0"
5
5
  end
@@ -98,9 +98,8 @@ RSpec.describe HTTP::Client do
98
98
  end
99
99
 
100
100
  it "works like a charm in real world" do
101
- url = "http://git.io/jNeY"
102
- client = HTTP.follow
103
- expect(client.get(url).to_s).to include "support for non-ascii URIs"
101
+ expect(HTTP.follow.get("https://bit.ly/2UaBT4R").parse(:json)).
102
+ to include("url" => "https://httpbin.org/anything/könig")
104
103
  end
105
104
  end
106
105
  end
@@ -190,6 +189,22 @@ RSpec.describe HTTP::Client do
190
189
 
191
190
  client.get("http://example.com/", :form => {:foo => HTTP::FormData::Part.new("content")})
192
191
  end
192
+
193
+ context "when passing an HTTP::FormData object directly" do
194
+ it "creates url encoded form data object" do
195
+ client = HTTP::Client.new
196
+ form_data = HTTP::FormData::Multipart.new(:foo => "bar")
197
+
198
+ allow(client).to receive(:perform)
199
+
200
+ expect(HTTP::Request).to receive(:new) do |opts|
201
+ expect(opts[:body]).to be form_data
202
+ expect(opts[:body].to_s).to match(/^Content-Disposition: form-data; name="foo"\r\n\r\nbar\r\n/m)
203
+ end
204
+
205
+ client.get("http://example.com/", :form => form_data)
206
+ end
207
+ end
193
208
  end
194
209
 
195
210
  describe "passing json" do
@@ -213,9 +228,9 @@ RSpec.describe HTTP::Client do
213
228
  end
214
229
 
215
230
  it "works like a charm in real world" do
216
- url = "https://github.com/httprb/http.rb/pull/197/ö無"
217
- client = HTTP.follow
218
- expect(client.get(url).to_s).to include "support for non-ascii URIs"
231
+ url = "https://httpbin.org/anything/ö無"
232
+
233
+ expect(HTTP.follow.get(url).parse(:json)).to include("url" => url)
219
234
  end
220
235
  end
221
236
 
@@ -75,6 +75,19 @@ RSpec.describe HTTP::Redirector do
75
75
  expect(res.to_s).to eq "foo"
76
76
  end
77
77
 
78
+ it "concatenates multiple Location headers" do
79
+ req = HTTP::Request.new :verb => :head, :uri => "http://example.com"
80
+ headers = HTTP::Headers.new
81
+
82
+ %w[http://example.com /123].each { |loc| headers.add("Location", loc) }
83
+
84
+ res = redirector.perform(req, simple_response(301, "", headers)) do |redirect|
85
+ simple_response(200, redirect.uri.to_s)
86
+ end
87
+
88
+ expect(res.to_s).to eq "http://example.com/123"
89
+ end
90
+
78
91
  context "following 300 redirect" do
79
92
  context "with strict mode" do
80
93
  let(:options) { {:strict => true} }
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: 4.3.0
4
+ version: 4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-01-09 00:00:00.000000000 Z
14
+ date: 2020-03-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: addressable
@@ -186,7 +186,7 @@ metadata:
186
186
  source_code_uri: https://github.com/httprb/http
187
187
  wiki_uri: https://github.com/httprb/http/wiki
188
188
  bug_tracker_uri: https://github.com/httprb/http/issues
189
- changelog_uri: https://github.com/httprb/http/blob/v4.3.0/CHANGES.md
189
+ changelog_uri: https://github.com/httprb/http/blob/v4.4.0/CHANGES.md
190
190
  post_install_message:
191
191
  rdoc_options: []
192
192
  require_paths:
@@ -202,7 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0'
204
204
  requirements: []
205
- rubygems_version: 3.0.3
205
+ rubyforge_project:
206
+ rubygems_version: 2.7.6.2
206
207
  signing_key:
207
208
  specification_version: 4
208
209
  summary: HTTP should be easy