http 4.0.2 → 4.0.3
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 +9 -0
- data/lib/http/features/auto_inflate.rb +20 -3
- data/lib/http/request.rb +12 -0
- data/lib/http/version.rb +1 -1
- data/spec/lib/http/features/auto_inflate_spec.rb +22 -2
- data/spec/lib/http/request_spec.rb +6 -0
- data/spec/lib/http/response_spec.rb +3 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11cd466b5be40e3caba90c9df54f90c3b927d4a3eae307b41f6c4e97fa0e453b
|
4
|
+
data.tar.gz: 33b04d19cdb16ff4ef7ac4e09b79266ccb9474f2bed845b70a25c1ae7382ee5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c8b29c85f85f64c0e6205df50cf96df6c60959ff770de9813119d1cc70a8e4fd7b70e5013980c5449b0076ef7dd0f906180d44b6037a930068997acbac2d45
|
7
|
+
data.tar.gz: aacd288d0353724d3c353ffebacbd4e34ea73f32102ced92e7b1c30e76ee12e1a7ae7ee48cc203239176ffac0bcb861c0ad5e990c3dfbd20c5197b45ca6472f0
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 4.0.3 (2019-01-18)
|
2
|
+
|
3
|
+
* Fix missing URL in response wrapped by auto inflate.
|
4
|
+
([@ixti])
|
5
|
+
|
6
|
+
* Provide `HTTP::Request#inspect` method for debugging purposes.
|
7
|
+
([@ixti])
|
8
|
+
|
9
|
+
|
1
10
|
## 4.0.2 (2019-01-15)
|
2
11
|
|
3
12
|
* [#506](https://github.com/httprb/http/pull/506)
|
@@ -1,24 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "set"
|
4
|
+
|
3
5
|
module HTTP
|
4
6
|
module Features
|
5
7
|
class AutoInflate < Feature
|
8
|
+
SUPPORTED_ENCODING = Set.new(%w[deflate gzip x-gzip]).freeze
|
9
|
+
private_constant :SUPPORTED_ENCODING
|
10
|
+
|
6
11
|
def wrap_response(response)
|
7
|
-
return response unless
|
8
|
-
|
12
|
+
return response unless supported_encoding?(response)
|
13
|
+
|
14
|
+
options = {
|
9
15
|
:status => response.status,
|
10
16
|
:version => response.version,
|
11
17
|
:headers => response.headers,
|
12
18
|
:proxy_headers => response.proxy_headers,
|
13
19
|
:connection => response.connection,
|
14
20
|
:body => stream_for(response.connection)
|
15
|
-
|
21
|
+
}
|
22
|
+
|
23
|
+
options[:uri] = response.uri if response.uri
|
24
|
+
|
25
|
+
Response.new(options)
|
16
26
|
end
|
17
27
|
|
18
28
|
def stream_for(connection)
|
19
29
|
Response::Body.new(Response::Inflater.new(connection))
|
20
30
|
end
|
21
31
|
|
32
|
+
private
|
33
|
+
|
34
|
+
def supported_encoding?(response)
|
35
|
+
content_encoding = response.headers.get(Headers::CONTENT_ENCODING).first
|
36
|
+
content_encoding && SUPPORTED_ENCODING.include?(content_encoding)
|
37
|
+
end
|
38
|
+
|
22
39
|
HTTP::Options.register_feature(:auto_inflate, self)
|
23
40
|
end
|
24
41
|
end
|
data/lib/http/request.rb
CHANGED
@@ -184,6 +184,18 @@ module HTTP
|
|
184
184
|
using_proxy? ? proxy[:proxy_port] : port
|
185
185
|
end
|
186
186
|
|
187
|
+
# Human-readable representation of base request info.
|
188
|
+
#
|
189
|
+
# @example
|
190
|
+
#
|
191
|
+
# req.inspect
|
192
|
+
# # => #<HTTP::Request/1.1 GET https://example.com>
|
193
|
+
#
|
194
|
+
# @return [String]
|
195
|
+
def inspect
|
196
|
+
"#<#{self.class}/#{@version} #{verb.to_s.upcase} #{uri}>"
|
197
|
+
end
|
198
|
+
|
187
199
|
private
|
188
200
|
|
189
201
|
# @!attribute [r] host
|
data/lib/http/version.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
RSpec.describe HTTP::Features::AutoInflate do
|
4
4
|
subject(:feature) { HTTP::Features::AutoInflate.new }
|
5
|
+
|
5
6
|
let(:connection) { double }
|
6
|
-
let(:headers)
|
7
|
+
let(:headers) { {} }
|
8
|
+
|
7
9
|
let(:response) do
|
8
10
|
HTTP::Response.new(
|
9
11
|
:version => "1.1",
|
@@ -13,7 +15,7 @@ RSpec.describe HTTP::Features::AutoInflate do
|
|
13
15
|
)
|
14
16
|
end
|
15
17
|
|
16
|
-
describe "wrap_response" do
|
18
|
+
describe "#wrap_response" do
|
17
19
|
subject(:result) { feature.wrap_response(response) }
|
18
20
|
|
19
21
|
context "when there is no Content-Encoding header" do
|
@@ -61,5 +63,23 @@ RSpec.describe HTTP::Features::AutoInflate do
|
|
61
63
|
expect(result.body).to be_instance_of HTTP::Response::Body
|
62
64
|
end
|
63
65
|
end
|
66
|
+
|
67
|
+
# TODO(ixti): We should refactor API to either make uri non-optional,
|
68
|
+
# or add reference to request into response object (better).
|
69
|
+
context "when response has uri" do
|
70
|
+
let(:response) do
|
71
|
+
HTTP::Response.new(
|
72
|
+
:version => "1.1",
|
73
|
+
:status => 200,
|
74
|
+
:headers => {:content_encoding => "gzip"},
|
75
|
+
:connection => connection,
|
76
|
+
:uri => "https://example.com"
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "preserves uri in wrapped response" do
|
81
|
+
expect(result.uri).to eq HTTP::URI.parse("https://example.com")
|
82
|
+
end
|
83
|
+
end
|
64
84
|
end
|
65
85
|
end
|
@@ -129,13 +129,12 @@ RSpec.describe HTTP::Response do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
describe "#inspect" do
|
132
|
+
subject { response.inspect }
|
133
|
+
|
132
134
|
let(:headers) { {:content_type => "text/plain"} }
|
133
135
|
let(:body) { double :to_s => "foobar" }
|
134
136
|
|
135
|
-
it
|
136
|
-
expect(response.inspect).
|
137
|
-
to eq '#<HTTP::Response/1.1 200 OK {"Content-Type"=>"text/plain"}>'
|
138
|
-
end
|
137
|
+
it { is_expected.to eq '#<HTTP::Response/1.1 200 OK {"Content-Type"=>"text/plain"}>' }
|
139
138
|
end
|
140
139
|
|
141
140
|
describe "#cookies" do
|
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.0.
|
4
|
+
version: 4.0.3
|
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: 2019-01-
|
14
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: http_parser.rb
|