http 2.0.2 → 2.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 +14 -0
- data/CONTRIBUTING.md +1 -0
- data/Gemfile +1 -0
- data/lib/http/request/writer.rb +2 -0
- data/lib/http/response.rb +17 -1
- data/lib/http/uri.rb +17 -14
- data/lib/http/version.rb +1 -1
- data/spec/lib/http/request/writer_spec.rb +18 -0
- data/spec/lib/http/response_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4daefc1ab609a814049d1dbb15c8b4dd1dcbc4af
|
4
|
+
data.tar.gz: 8e997cb150a1b40c3f93713a8c0a8e0c3c347e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14aa2d7853ca5d3b0c4a60f3d85ea79ce29f942cae40d60c83cfa9de10845806b521cece91aabff8954f2bfd33ccd78577f39676133d5dee45f7055b0083e599
|
7
|
+
data.tar.gz: 9473c747c14dc40eb7ee6a9822bf45b674a8892c8cc92db6cfa9d88fa9bc3d6f03429e72609d6e902fdaed836c38e80fc6ba0d5d58c53a2a688a98fb365deaf1
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 2.0.3 (2016-08-03)
|
2
|
+
|
3
|
+
* [#365](https://github.com/httprb/http/issues/365)
|
4
|
+
Add `HTTP::Response#content_length`
|
5
|
+
([@janko-m])
|
6
|
+
|
7
|
+
* [#335](https://github.com/httprb/http/issues/335),
|
8
|
+
[#360](https://github.com/httprb/http/pull/360)
|
9
|
+
Set `Content-Length: 0` header for `nil` bodies.
|
10
|
+
([@britishtea])
|
11
|
+
|
12
|
+
|
1
13
|
## 2.0.2 (2016-06-24)
|
2
14
|
|
3
15
|
* [#353](https://github.com/httprb/http/pull/353)
|
@@ -537,3 +549,5 @@ end
|
|
537
549
|
[@mwitek]: https://github.com/mwitek
|
538
550
|
[@tonyta]: https://github.com/tonyta
|
539
551
|
[@jhbabon]: https://github.com/jhbabon
|
552
|
+
[@britishtea]: https://github.com/britishtea
|
553
|
+
[@janko-m]: https://github.com/janko-m
|
data/CONTRIBUTING.md
CHANGED
data/Gemfile
CHANGED
data/lib/http/request/writer.rb
CHANGED
@@ -53,6 +53,8 @@ module HTTP
|
|
53
53
|
def add_body_type_headers
|
54
54
|
if @body.is_a?(String) && !@headers[Headers::CONTENT_LENGTH]
|
55
55
|
@request_header << "#{Headers::CONTENT_LENGTH}: #{@body.bytesize}"
|
56
|
+
elsif @body.nil? && !@headers[Headers::CONTENT_LENGTH]
|
57
|
+
@request_header << "#{Headers::CONTENT_LENGTH}: 0"
|
56
58
|
elsif @body.is_a?(Enumerable) && CHUNKED != @headers[Headers::TRANSFER_ENCODING]
|
57
59
|
raise(RequestError, "invalid transfer encoding")
|
58
60
|
end
|
data/lib/http/response.rb
CHANGED
@@ -86,6 +86,22 @@ module HTTP
|
|
86
86
|
self
|
87
87
|
end
|
88
88
|
|
89
|
+
# Value of the Content-Length header.
|
90
|
+
#
|
91
|
+
# @return [nil] if Content-Length was not given, or it's value was invalid
|
92
|
+
# (not an integer, e.g. empty string or string with non-digits).
|
93
|
+
# @return [Integer] otherwise
|
94
|
+
def content_length
|
95
|
+
value = @headers[Headers::CONTENT_LENGTH]
|
96
|
+
return unless value
|
97
|
+
|
98
|
+
begin
|
99
|
+
Integer(value)
|
100
|
+
rescue ArgumentError
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
89
105
|
# Parsed Content-Type header
|
90
106
|
#
|
91
107
|
# @return [HTTP::ContentType]
|
@@ -113,7 +129,7 @@ module HTTP
|
|
113
129
|
#
|
114
130
|
# @param [#to_s] as Parse as given MIME type
|
115
131
|
# instead of the one determined from headers
|
116
|
-
# @raise [Error] if adapter not found
|
132
|
+
# @raise [HTTP::Error] if adapter not found
|
117
133
|
# @return [Object]
|
118
134
|
def parse(as = nil)
|
119
135
|
MimeType[as || mime_type].decode to_s
|
data/lib/http/uri.rb
CHANGED
@@ -26,7 +26,7 @@ module HTTP
|
|
26
26
|
|
27
27
|
# Parse the given URI string, returning an HTTP::URI object
|
28
28
|
#
|
29
|
-
# @param [HTTP::URI, String, #to_str]
|
29
|
+
# @param [HTTP::URI, String, #to_str] uri to parse
|
30
30
|
#
|
31
31
|
# @return [HTTP::URI] new URI instance
|
32
32
|
def self.parse(uri)
|
@@ -37,8 +37,8 @@ module HTTP
|
|
37
37
|
|
38
38
|
# Encodes key/value pairs as application/x-www-form-urlencoded
|
39
39
|
#
|
40
|
-
# @param [#to_hash, #to_ary]
|
41
|
-
# @param [TrueClass, FalseClass]
|
40
|
+
# @param [#to_hash, #to_ary] form_values to encode
|
41
|
+
# @param [TrueClass, FalseClass] sort should key/value pairs be sorted first?
|
42
42
|
#
|
43
43
|
# @return [String] encoded value
|
44
44
|
def self.form_encode(form_values, sort = false)
|
@@ -47,14 +47,16 @@ module HTTP
|
|
47
47
|
|
48
48
|
# Creates an HTTP::URI instance from the given options
|
49
49
|
#
|
50
|
-
# @
|
51
|
-
#
|
52
|
-
# @option [String, #to_str] :
|
53
|
-
# @option [String, #to_str] :
|
54
|
-
# @option [String, #to_str] :
|
55
|
-
# @option [String, #to_str] :
|
56
|
-
# @option [String, #to_str] :
|
57
|
-
# @option [String, #to_str] :
|
50
|
+
# @param [Hash, Addressable::URI] options_or_uri
|
51
|
+
#
|
52
|
+
# @option options_or_uri [String, #to_str] :scheme URI scheme
|
53
|
+
# @option options_or_uri [String, #to_str] :user for basic authentication
|
54
|
+
# @option options_or_uri [String, #to_str] :password for basic authentication
|
55
|
+
# @option options_or_uri [String, #to_str] :host name component
|
56
|
+
# @option options_or_uri [String, #to_str] :port network port to connect to
|
57
|
+
# @option options_or_uri [String, #to_str] :path component to request
|
58
|
+
# @option options_or_uri [String, #to_str] :query component distinct from path
|
59
|
+
# @option options_or_uri [String, #to_str] :fragment component at the end of the URI
|
58
60
|
#
|
59
61
|
# @return [HTTP::URI] new URI instance
|
60
62
|
def initialize(options_or_uri = {})
|
@@ -63,13 +65,14 @@ module HTTP
|
|
63
65
|
@uri = Addressable::URI.new(options_or_uri)
|
64
66
|
when Addressable::URI
|
65
67
|
@uri = options_or_uri
|
66
|
-
else
|
68
|
+
else
|
69
|
+
raise TypeError, "expected Hash for options, got #{options_or_uri.class}"
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
70
73
|
# Are these URI objects equal? Normalizes both URIs prior to comparison
|
71
74
|
#
|
72
|
-
# @param [Object]
|
75
|
+
# @param [Object] other URI to compare this one with
|
73
76
|
#
|
74
77
|
# @return [TrueClass, FalseClass] are the URIs equivalent (after normalization)?
|
75
78
|
def ==(other)
|
@@ -78,7 +81,7 @@ module HTTP
|
|
78
81
|
|
79
82
|
# Are these URI objects equal? Does NOT normalizes both URIs prior to comparison
|
80
83
|
#
|
81
|
-
# @param [Object]
|
84
|
+
# @param [Object] other URI to compare this one with
|
82
85
|
#
|
83
86
|
# @return [TrueClass, FalseClass] are the URIs equivalent?
|
84
87
|
def eql?(other)
|
data/lib/http/version.rb
CHANGED
@@ -69,6 +69,24 @@ RSpec.describe HTTP::Request::Writer do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
context "when body is nil" do
|
73
|
+
let(:body) { nil }
|
74
|
+
|
75
|
+
it "properly sets Content-Length header if needed" do
|
76
|
+
writer.stream
|
77
|
+
expect(io.string).to start_with "#{headerstart}\r\nContent-Length: 0\r\n\r\n"
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when Content-Length explicitly set" do
|
81
|
+
let(:headers) { HTTP::Headers.coerce "Content-Length" => 12 }
|
82
|
+
|
83
|
+
it "keeps given value" do
|
84
|
+
writer.stream
|
85
|
+
expect(io.string).to start_with "#{headerstart}\r\nContent-Length: 12\r\n\r\n"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
72
90
|
context "when body is a unicode String" do
|
73
91
|
let(:body) { "Привет, мир!" }
|
74
92
|
|
@@ -28,6 +28,24 @@ RSpec.describe HTTP::Response do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
describe "#content_length" do
|
32
|
+
subject { response.content_length }
|
33
|
+
|
34
|
+
context "without Content-Length header" do
|
35
|
+
it { is_expected.to be_nil }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with Content-Length: 5" do
|
39
|
+
let(:headers) { {"Content-Length" => "5"} }
|
40
|
+
it { is_expected.to eq 5 }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with invalid Content-Length" do
|
44
|
+
let(:headers) { {"Content-Length" => "foo"} }
|
45
|
+
it { is_expected.to be_nil }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
31
49
|
describe "mime_type" do
|
32
50
|
subject { response.mime_type }
|
33
51
|
|
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: 2.0.
|
4
|
+
version: 2.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: 2016-
|
14
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: http_parser.rb
|