protocol-http 0.14.4 → 0.15.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 +4 -4
- data/lib/protocol/http/body/buffered.rb +18 -2
- data/lib/protocol/http/body/head.rb +51 -0
- data/lib/protocol/http/body/readable.rb +5 -2
- data/lib/protocol/http/body/streamable.rb +3 -20
- data/lib/protocol/http/request.rb +12 -4
- data/lib/protocol/http/url.rb +1 -0
- data/lib/protocol/http/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af6588e75cd95086183ad1e1d27a4c70d2a59d284b7640cbe3d22b7630c3318
|
4
|
+
data.tar.gz: a03a42a4d0bda22e902a66720d884a53351a298e8637744463e653415ca7e0b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8c7ecb9521a14e3f17e471fb3a805bb4b6b58ef29fcddce709e633ab2dd5a2ac3cc1c0673ac45947766ec888caae7c604dc510c920a187b23fe0a66d88d063c
|
7
|
+
data.tar.gz: ee2cd54ee6b2f2a864ad193706c1f46ba116b755da6b31d118224b6c2ada54df331803e9bc36089667a3f105bce14810bb44ae6d2ce1246b5857163ee988f56a
|
@@ -22,6 +22,8 @@
|
|
22
22
|
|
23
23
|
require_relative 'readable'
|
24
24
|
|
25
|
+
require 'digest/sha2'
|
26
|
+
|
25
27
|
module Protocol
|
26
28
|
module HTTP
|
27
29
|
module Body
|
@@ -30,9 +32,9 @@ module Protocol
|
|
30
32
|
# Wraps an array into a buffered body.
|
31
33
|
# @return [Readable, nil] the wrapped body or nil if nil was given.
|
32
34
|
def self.wrap(body)
|
33
|
-
if body.is_a?
|
35
|
+
if body.is_a?(Readable)
|
34
36
|
return body
|
35
|
-
elsif body.is_a?
|
37
|
+
elsif body.is_a?(Array)
|
36
38
|
return self.new(body)
|
37
39
|
elsif body.is_a?(String)
|
38
40
|
return self.new([body])
|
@@ -56,6 +58,11 @@ module Protocol
|
|
56
58
|
@length = length
|
57
59
|
|
58
60
|
@index = 0
|
61
|
+
@digest = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def digest
|
65
|
+
@digest ||= compute_digest
|
59
66
|
end
|
60
67
|
|
61
68
|
def finish
|
@@ -79,6 +86,7 @@ module Protocol
|
|
79
86
|
end
|
80
87
|
|
81
88
|
def write(chunk)
|
89
|
+
@digest = nil
|
82
90
|
@chunks << chunk
|
83
91
|
end
|
84
92
|
|
@@ -89,6 +97,14 @@ module Protocol
|
|
89
97
|
def inspect
|
90
98
|
"\#<#{self.class} #{@chunks.size} chunks, #{self.length} bytes>"
|
91
99
|
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def compute_digest
|
104
|
+
algorithm = Digest::SHA256.new
|
105
|
+
@chunks.each{|chunk| algorithm.update(chunk)}
|
106
|
+
return algorithm.hexdigest
|
107
|
+
end
|
92
108
|
end
|
93
109
|
end
|
94
110
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative 'readable'
|
24
|
+
|
25
|
+
module Protocol
|
26
|
+
module HTTP
|
27
|
+
module Body
|
28
|
+
class Head < Readable
|
29
|
+
def self.for(body)
|
30
|
+
head = self.new(body.length)
|
31
|
+
|
32
|
+
body.close
|
33
|
+
|
34
|
+
return head
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(length)
|
38
|
+
@length = length
|
39
|
+
end
|
40
|
+
|
41
|
+
def empty?
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def length
|
46
|
+
@length
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -63,7 +63,6 @@ module Protocol
|
|
63
63
|
def each
|
64
64
|
while chunk = self.read
|
65
65
|
yield chunk
|
66
|
-
# chunk.clear
|
67
66
|
end
|
68
67
|
ensure
|
69
68
|
self.close($!)
|
@@ -78,7 +77,11 @@ module Protocol
|
|
78
77
|
chunk.clear
|
79
78
|
end
|
80
79
|
|
81
|
-
|
80
|
+
if buffer.empty?
|
81
|
+
return nil
|
82
|
+
else
|
83
|
+
return buffer
|
84
|
+
end
|
82
85
|
end
|
83
86
|
end
|
84
87
|
end
|
@@ -28,22 +28,17 @@ module Protocol
|
|
28
28
|
# Invokes a callback once the body has finished reading.
|
29
29
|
class Streamable < Wrapper
|
30
30
|
def self.wrap(message, &block)
|
31
|
-
if body = message&.body
|
32
|
-
|
33
|
-
remaining = Integer(remaining)
|
34
|
-
end
|
35
|
-
|
36
|
-
message.body = self.new(message.body, block, remaining)
|
31
|
+
if body = message&.body and !body.empty?
|
32
|
+
message.body = self.new(message.body, block)
|
37
33
|
else
|
38
34
|
yield
|
39
35
|
end
|
40
36
|
end
|
41
37
|
|
42
|
-
def initialize(body, callback
|
38
|
+
def initialize(body, callback)
|
43
39
|
super(body)
|
44
40
|
|
45
41
|
@callback = callback
|
46
|
-
@remaining = remaining
|
47
42
|
end
|
48
43
|
|
49
44
|
def finish
|
@@ -67,18 +62,6 @@ module Protocol
|
|
67
62
|
@body = nil
|
68
63
|
end
|
69
64
|
end
|
70
|
-
|
71
|
-
def read
|
72
|
-
if chunk = super
|
73
|
-
@remaining -= chunk.bytesize if @remaining
|
74
|
-
else
|
75
|
-
if @remaining and @remaining > 0
|
76
|
-
raise EOFError, "Expected #{@remaining} more bytes!"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
return chunk
|
81
|
-
end
|
82
65
|
end
|
83
66
|
end
|
84
67
|
end
|
@@ -28,11 +28,11 @@ module Protocol
|
|
28
28
|
class Request
|
29
29
|
prepend Body::Reader
|
30
30
|
|
31
|
-
def initialize(scheme = nil, authority = nil, method = nil,
|
31
|
+
def initialize(scheme = nil, authority = nil, method = nil, target = nil, version = nil, headers = [], body = nil, protocol = nil)
|
32
32
|
@scheme = scheme
|
33
33
|
@authority = authority
|
34
34
|
@method = method
|
35
|
-
@
|
35
|
+
@target = target
|
36
36
|
@version = version
|
37
37
|
@headers = headers
|
38
38
|
@body = body
|
@@ -42,7 +42,7 @@ module Protocol
|
|
42
42
|
attr_accessor :scheme
|
43
43
|
attr_accessor :authority
|
44
44
|
attr_accessor :method
|
45
|
-
attr_accessor :
|
45
|
+
attr_accessor :target
|
46
46
|
attr_accessor :version
|
47
47
|
attr_accessor :headers
|
48
48
|
attr_accessor :body
|
@@ -53,6 +53,14 @@ module Protocol
|
|
53
53
|
connection.call(self)
|
54
54
|
end
|
55
55
|
|
56
|
+
def path
|
57
|
+
@target
|
58
|
+
end
|
59
|
+
|
60
|
+
def path= value
|
61
|
+
@target = value
|
62
|
+
end
|
63
|
+
|
56
64
|
def head?
|
57
65
|
@method == Methods::HEAD
|
58
66
|
end
|
@@ -72,7 +80,7 @@ module Protocol
|
|
72
80
|
end
|
73
81
|
|
74
82
|
def to_s
|
75
|
-
"#{@scheme}://#{@authority}: #{@method} #{@
|
83
|
+
"#{@scheme}://#{@authority}: #{@method} #{@target} #{@version}"
|
76
84
|
end
|
77
85
|
end
|
78
86
|
end
|
data/lib/protocol/http/url.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.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-03-
|
11
|
+
date: 2020-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: covered
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/protocol/http/body/buffered.rb
|
86
86
|
- lib/protocol/http/body/deflate.rb
|
87
87
|
- lib/protocol/http/body/file.rb
|
88
|
+
- lib/protocol/http/body/head.rb
|
88
89
|
- lib/protocol/http/body/inflate.rb
|
89
90
|
- lib/protocol/http/body/readable.rb
|
90
91
|
- lib/protocol/http/body/reader.rb
|