http 4.4.0 → 4.4.1

This diff has not been reviewed by any users.
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c303ff626f5b57ed080d5d64d3ba7fd0a9eed5bc9463ff1035b1386dad36a9ab
4
- data.tar.gz: 3bc824e2ab723de39556166ec821d8c9a3f14dc5bc8dd542e4ccadf916a2518a
3
+ metadata.gz: cce9a8685f3b60f994e77174f79c2306f607d62016bf64b74fcebc4f86377ec0
4
+ data.tar.gz: 353702b62a1b9d3b2ea86ac5ac3ad88e9efa734c77e180128fa06c6c301895d3
5
5
  SHA512:
6
- metadata.gz: 9e78a6c25816e48f36394d3e4d612d94b47eb45787ca74a1fd5f49372c3df1037e535a401392a3318bfcc7194a1afee361794aadab853ae420054f00015101d0
7
- data.tar.gz: 9e1656f514777d0c5c149b273d9276b3c2affb93363c3cbc74a20c1a7fed039148564adad891459eac012415d4d1dee98238bcf3e6a0f3e978fa4263afa4925b
6
+ metadata.gz: 84ddc4cf98e603d175a9ecb8db03abd32187888070abd96a437c4121750ac2b86b6cada5d00d527b398ff4a403c2b6448d45bed61c45dbd3be8658f4ad38b121
7
+ data.tar.gz: 750edced9ae715483d750f0b18777f84a4ee24848ec761c67d2c5b89d00ebbc99fbc1e02932d3d30a33eaea43e1d081ba97bcacaf2231f6693e50d218ee24e87
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 4.4.1 (2020-03-29)
2
+
3
+ * Backport [#590](https://github.com/httprb/http/pull/590)
4
+ Fix parser failing on some edge cases.
5
+ ([@ixti])
6
+
1
7
  ## 4.4.0 (2020-03-25)
2
8
 
3
9
  * Backport [#587](https://github.com/httprb/http/pull/587)
@@ -49,14 +49,17 @@ module HTTP
49
49
  #
50
50
 
51
51
  def on_header_field(_response, field)
52
- @field = field
52
+ append_header if @reading_header_value
53
+ @field << field
53
54
  end
54
55
 
55
56
  def on_header_value(_response, value)
56
- @headers.add(@field, value) if @field
57
+ @reading_header_value = true
58
+ @field_value << value
57
59
  end
58
60
 
59
61
  def on_headers_complete(_reposse)
62
+ append_header if @reading_header_value
60
63
  @finished[:headers] = true
61
64
  end
62
65
 
@@ -89,15 +92,26 @@ module HTTP
89
92
  def reset
90
93
  @state.reset!
91
94
 
92
- @finished = Hash.new(false)
93
- @headers = HTTP::Headers.new
94
- @field = nil
95
- @chunk = nil
95
+ @finished = Hash.new(false)
96
+ @headers = HTTP::Headers.new
97
+ @reading_header_value = false
98
+ @field = +""
99
+ @field_value = +""
100
+ @chunk = nil
96
101
  end
97
102
 
98
103
  def finished?
99
104
  @finished[:message]
100
105
  end
106
+
107
+ private
108
+
109
+ def append_header
110
+ @headers.add(@field, @field_value)
111
+ @reading_header_value = false
112
+ @field_value = +""
113
+ @field = +""
114
+ end
101
115
  end
102
116
  end
103
117
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTP
4
- VERSION = "4.4.0"
4
+ VERSION = "4.4.1"
5
5
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe HTTP::Response::Parser do
4
+ subject(:parser) { described_class.new }
5
+ let(:raw_response) do
6
+ "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\nMy-Header: val\r\nEmpty-Header: \r\n\r\n{}"
7
+ end
8
+ let(:expected_headers) do
9
+ {
10
+ "Content-Length" => "2",
11
+ "Content-Type" => "application/json",
12
+ "My-Header" => "val",
13
+ "Empty-Header" => ""
14
+ }
15
+ end
16
+ let(:expected_body) { "{}" }
17
+
18
+ before do
19
+ parts.each { |part| subject.add(part) }
20
+ end
21
+
22
+ context "whole response in one part" do
23
+ let(:parts) { [raw_response] }
24
+
25
+ it "parses headers" do
26
+ expect(subject.headers.to_h).to eq(expected_headers)
27
+ end
28
+
29
+ it "parses body" do
30
+ expect(subject.read(expected_body.size)).to eq(expected_body)
31
+ end
32
+ end
33
+
34
+ context "response in many parts" do
35
+ let(:parts) { raw_response.split(//) }
36
+
37
+ it "parses headers" do
38
+ expect(subject.headers.to_h).to eq(expected_headers)
39
+ end
40
+
41
+ it "parses body" do
42
+ expect(subject.read(expected_body.size)).to eq(expected_body)
43
+ end
44
+ end
45
+ end
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.4.0
4
+ version: 4.4.1
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-03-25 00:00:00.000000000 Z
14
+ date: 2020-03-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: addressable
@@ -163,6 +163,7 @@ files:
163
163
  - spec/lib/http/request/writer_spec.rb
164
164
  - spec/lib/http/request_spec.rb
165
165
  - spec/lib/http/response/body_spec.rb
166
+ - spec/lib/http/response/parser_spec.rb
166
167
  - spec/lib/http/response/status_spec.rb
167
168
  - spec/lib/http/response_spec.rb
168
169
  - spec/lib/http/uri_spec.rb
@@ -186,7 +187,7 @@ metadata:
186
187
  source_code_uri: https://github.com/httprb/http
187
188
  wiki_uri: https://github.com/httprb/http/wiki
188
189
  bug_tracker_uri: https://github.com/httprb/http/issues
189
- changelog_uri: https://github.com/httprb/http/blob/v4.4.0/CHANGES.md
190
+ changelog_uri: https://github.com/httprb/http/blob/v4.4.1/CHANGES.md
190
191
  post_install_message:
191
192
  rdoc_options: []
192
193
  require_paths:
@@ -202,8 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
203
  - !ruby/object:Gem::Version
203
204
  version: '0'
204
205
  requirements: []
205
- rubyforge_project:
206
- rubygems_version: 2.7.6.2
206
+ rubygems_version: 3.0.3
207
207
  signing_key:
208
208
  specification_version: 4
209
209
  summary: HTTP should be easy
@@ -231,6 +231,7 @@ test_files:
231
231
  - spec/lib/http/request/writer_spec.rb
232
232
  - spec/lib/http/request_spec.rb
233
233
  - spec/lib/http/response/body_spec.rb
234
+ - spec/lib/http/response/parser_spec.rb
234
235
  - spec/lib/http/response/status_spec.rb
235
236
  - spec/lib/http/response_spec.rb
236
237
  - spec/lib/http/uri_spec.rb