protocol-http1 0.10.3 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of protocol-http1 might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/lib/protocol/http1/body/chunked.rb +30 -6
- data/lib/protocol/http1/connection.rb +15 -8
- data/lib/protocol/http1/version.rb +1 -1
- data/protocol-http1.gemspec +2 -2
- metadata +9 -10
- data/Rakefile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd207477ff1c6e86ccc2a90b3ec7ae27c7a3f5dbfd58e42cf78fb841638d43c1
|
4
|
+
data.tar.gz: 797536146daeb57ce4b40cf4e71bbcea02cc49067ecdd05d1c1b9c55f768212d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0efd8f411bc383b88694116c674376acd8d9fd9871aa4d3a89bfa95a39b0124aa2577c1c3767a11eed91f310bb0581f07c8f80b20ab2a79033db534028b346ce
|
7
|
+
data.tar.gz: 4e1836661c69a4dbe0cc42ac961afd76153e07f5a41f83428a8d37673924a05cbc9795daa1cc14f530bb38815cee374b61e2dbe105e6df21fafade35a103d6e2
|
data/.travis.yml
CHANGED
@@ -26,11 +26,15 @@ module Protocol
|
|
26
26
|
module HTTP1
|
27
27
|
module Body
|
28
28
|
class Chunked < HTTP::Body::Readable
|
29
|
-
|
30
|
-
|
29
|
+
TRAILERS = 'trailers'
|
30
|
+
CRLF = "\r\n"
|
31
|
+
|
32
|
+
def initialize(stream, headers)
|
31
33
|
@stream = stream
|
32
34
|
@finished = false
|
33
35
|
|
36
|
+
@headers = headers
|
37
|
+
|
34
38
|
@length = 0
|
35
39
|
@count = 0
|
36
40
|
end
|
@@ -49,6 +53,7 @@ module Protocol
|
|
49
53
|
super
|
50
54
|
end
|
51
55
|
|
56
|
+
# Follows the procedure outlined in https://tools.ietf.org/html/rfc7230#section-4.1.3
|
52
57
|
def read
|
53
58
|
return nil if @finished
|
54
59
|
|
@@ -56,13 +61,17 @@ module Protocol
|
|
56
61
|
|
57
62
|
if length == 0
|
58
63
|
@finished = true
|
59
|
-
|
64
|
+
|
65
|
+
read_trailers
|
60
66
|
|
61
67
|
return nil
|
62
68
|
end
|
63
69
|
|
64
|
-
|
65
|
-
|
70
|
+
# Read trailing CRLF:
|
71
|
+
chunk = @stream.read(length + 2)
|
72
|
+
|
73
|
+
# ...and chomp it off:
|
74
|
+
chunk.chomp!(CRLF)
|
66
75
|
|
67
76
|
@length += length
|
68
77
|
@count += 1
|
@@ -77,7 +86,22 @@ module Protocol
|
|
77
86
|
private
|
78
87
|
|
79
88
|
def read_line
|
80
|
-
@stream.gets(chomp: true)
|
89
|
+
@stream.gets(CRLF, chomp: true)
|
90
|
+
end
|
91
|
+
|
92
|
+
def read_trailers
|
93
|
+
@headers.trailers!
|
94
|
+
|
95
|
+
while line = read_line
|
96
|
+
# Empty line indicates end of headers:
|
97
|
+
break if line.empty?
|
98
|
+
|
99
|
+
if match = line.match(HEADER)
|
100
|
+
@headers.add(match[1], match[2])
|
101
|
+
else
|
102
|
+
raise BadHeader, "Could not parse header: #{line.dump}"
|
103
|
+
end
|
104
|
+
end
|
81
105
|
end
|
82
106
|
end
|
83
107
|
end
|
@@ -307,7 +307,7 @@ module Protocol
|
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
310
|
-
def write_chunked_body(body, head)
|
310
|
+
def write_chunked_body(body, head, trailers = nil)
|
311
311
|
@stream.write("transfer-encoding: chunked\r\n\r\n")
|
312
312
|
@stream.flush
|
313
313
|
|
@@ -326,7 +326,14 @@ module Protocol
|
|
326
326
|
@stream.flush
|
327
327
|
end
|
328
328
|
|
329
|
-
|
329
|
+
if trailers
|
330
|
+
@stream.write("0\r\n")
|
331
|
+
write_headers(trailers)
|
332
|
+
@stream.write("\r\n")
|
333
|
+
else
|
334
|
+
@stream.write("0\r\n\r\n")
|
335
|
+
end
|
336
|
+
|
330
337
|
@stream.flush
|
331
338
|
end
|
332
339
|
|
@@ -349,7 +356,7 @@ module Protocol
|
|
349
356
|
@stream.close_write
|
350
357
|
end
|
351
358
|
|
352
|
-
def write_body(version, body, head = false)
|
359
|
+
def write_body(version, body, head = false, trailers = nil)
|
353
360
|
if body.nil? or body.empty?
|
354
361
|
write_connection_header(version)
|
355
362
|
write_empty_body(body)
|
@@ -359,7 +366,7 @@ module Protocol
|
|
359
366
|
elsif @persistent and version == HTTP11
|
360
367
|
write_connection_header(version)
|
361
368
|
# We specifically ensure that non-persistent connections do not use chunked response, so that hijacking works as expected.
|
362
|
-
write_chunked_body(body, head)
|
369
|
+
write_chunked_body(body, head, trailers)
|
363
370
|
else
|
364
371
|
@persistent = false
|
365
372
|
write_connection_header(version)
|
@@ -367,8 +374,8 @@ module Protocol
|
|
367
374
|
end
|
368
375
|
end
|
369
376
|
|
370
|
-
def read_chunked_body
|
371
|
-
Body::Chunked.new(@stream)
|
377
|
+
def read_chunked_body(headers)
|
378
|
+
Body::Chunked.new(@stream, headers)
|
372
379
|
end
|
373
380
|
|
374
381
|
def read_fixed_body(length)
|
@@ -466,7 +473,7 @@ module Protocol
|
|
466
473
|
end
|
467
474
|
|
468
475
|
if transfer_encoding.last == CHUNKED
|
469
|
-
return read_chunked_body
|
476
|
+
return read_chunked_body(headers)
|
470
477
|
else
|
471
478
|
# If a Transfer-Encoding header field is present in a response and
|
472
479
|
# the chunked transfer coding is not the final encoding, the
|
@@ -479,7 +486,7 @@ module Protocol
|
|
479
486
|
return read_remainder_body
|
480
487
|
end
|
481
488
|
end
|
482
|
-
|
489
|
+
|
483
490
|
# 5. If a valid Content-Length header field is present without
|
484
491
|
# Transfer-Encoding, its decimal value defines the expected message
|
485
492
|
# body length in octets. If the sender closes the connection or
|
data/protocol-http1.gemspec
CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency "protocol-http", "~> 0.
|
23
|
+
spec.add_dependency "protocol-http", "~> 0.16.3"
|
24
24
|
|
25
25
|
spec.add_development_dependency "covered"
|
26
26
|
spec.add_development_dependency "bundler"
|
27
|
-
spec.add_development_dependency "
|
27
|
+
spec.add_development_dependency "bake-bundler"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
spec.add_development_dependency "rspec-memory", "~> 1.0"
|
30
30
|
spec.add_development_dependency "rspec-files", "~> 1.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: protocol-http
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.16.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.16.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: covered
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bake-bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- ".travis.yml"
|
122
122
|
- Gemfile
|
123
123
|
- README.md
|
124
|
-
- Rakefile
|
125
124
|
- examples/http1/request.rb
|
126
125
|
- lib/protocol/http1.rb
|
127
126
|
- lib/protocol/http1/body/chunked.rb
|