protocol-http 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/protocol/http/headers.rb +45 -13
- data/lib/protocol/http/methods.rb +1 -1
- data/lib/protocol/http/request.rb +1 -7
- data/lib/protocol/http/response.rb +2 -8
- data/lib/protocol/http/version.rb +1 -1
- 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: d8d2f576f6e7e6ce261d80fbdc0e38e2775b2f22ac156958b1e1b91472fdfec3
|
4
|
+
data.tar.gz: b450d401f5791db371761fd52a6c1adb32807a13659570a1ad0ef0d5ef3dd8d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0be25839110052bd336f729800768eb8d8ef51bf15c2852b9bc526e20a6998177dadfc4e71b889681b16ba263f25dc14ea42e0835ce4f87de7d343936ff91ea8
|
7
|
+
data.tar.gz: bf48aa19e331906fcf518eed7c6c94243656856f034d6c44a90ecf41c0bd1807c1a540d836fc61d63d6cd3acc2a769b37f1898b608296578edc45866747659a6
|
@@ -35,16 +35,31 @@ module Protocol
|
|
35
35
|
class Headers
|
36
36
|
Split = Header::Split
|
37
37
|
Multiple = Header::Multiple
|
38
|
+
|
38
39
|
TRAILERS = 'trailers'
|
39
40
|
|
40
|
-
# Construct an instance from a headers Array or Hash. No-op if already an instance of `Headers`.
|
41
|
+
# Construct an instance from a headers Array or Hash. No-op if already an instance of `Headers`. If the underlying array is frozen, it will be duped.
|
41
42
|
# @return [Headers] an instance of headers.
|
42
43
|
def self.[] headers
|
44
|
+
if headers.nil?
|
45
|
+
return self.new
|
46
|
+
end
|
47
|
+
|
43
48
|
if headers.is_a?(self)
|
44
|
-
headers
|
45
|
-
|
46
|
-
|
49
|
+
if headers.frozen?
|
50
|
+
return headers.dup
|
51
|
+
else
|
52
|
+
return headers
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
fields = headers.to_a
|
57
|
+
|
58
|
+
if fields.frozen?
|
59
|
+
fields = fields.dup
|
47
60
|
end
|
61
|
+
|
62
|
+
return self.new(fields)
|
48
63
|
end
|
49
64
|
|
50
65
|
def initialize(fields = [], indexed = nil)
|
@@ -60,7 +75,6 @@ module Protocol
|
|
60
75
|
|
61
76
|
@fields = @fields.dup
|
62
77
|
@indexed = @indexed.dup
|
63
|
-
@tail = nil
|
64
78
|
end
|
65
79
|
|
66
80
|
def clear
|
@@ -69,25 +83,43 @@ module Protocol
|
|
69
83
|
@tail = nil
|
70
84
|
end
|
71
85
|
|
72
|
-
#
|
73
|
-
|
86
|
+
# Flatten trailers into the headers.
|
87
|
+
def flatten!
|
88
|
+
if @tail
|
89
|
+
self.delete(TRAILERS)
|
90
|
+
@tail = nil
|
91
|
+
end
|
92
|
+
|
93
|
+
return self
|
94
|
+
end
|
74
95
|
|
75
|
-
|
76
|
-
|
77
|
-
@tail ||= @fields.size
|
96
|
+
def flatten
|
97
|
+
self.dup.flatten!
|
78
98
|
end
|
79
99
|
|
100
|
+
# An array of `[key, value]` pairs.
|
101
|
+
attr :fields
|
102
|
+
|
80
103
|
# @return the trailers if there are any.
|
81
104
|
def trailers?
|
82
105
|
@tail != nil
|
83
106
|
end
|
84
107
|
|
85
|
-
#
|
86
|
-
def trailers(&block)
|
108
|
+
# Record the current headers, and prepare to receive trailers.
|
109
|
+
def trailers!(&block)
|
87
110
|
return nil unless self.include?(TRAILERS)
|
88
111
|
|
89
|
-
|
112
|
+
@tail ||= @fields.size
|
90
113
|
|
114
|
+
return to_enum(:trailers!) unless block_given?
|
115
|
+
|
116
|
+
if @tail
|
117
|
+
@fields.drop(@tail).each(&block)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Enumerate all trailers, if there are any.
|
122
|
+
def trailers(&block)
|
91
123
|
return to_enum(:trailers) unless block_given?
|
92
124
|
|
93
125
|
if @tail
|
@@ -51,7 +51,7 @@ module Protocol
|
|
51
51
|
|
52
52
|
# Use Methods.constants to get all constants.
|
53
53
|
self.each do |name, value|
|
54
|
-
define_method(name.downcase) do |location, headers =
|
54
|
+
define_method(name.downcase) do |location, headers = nil, body = nil|
|
55
55
|
self.call(
|
56
56
|
Request[value, location.to_str, Headers[headers], body]
|
57
57
|
)
|
@@ -28,7 +28,7 @@ module Protocol
|
|
28
28
|
class Request
|
29
29
|
prepend Body::Reader
|
30
30
|
|
31
|
-
def initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers =
|
31
|
+
def initialize(scheme = nil, authority = nil, method = nil, path = nil, version = nil, headers = Headers.new, body = nil, protocol = nil)
|
32
32
|
@scheme = scheme
|
33
33
|
@authority = authority
|
34
34
|
@method = method
|
@@ -48,12 +48,6 @@ module Protocol
|
|
48
48
|
attr_accessor :body
|
49
49
|
attr_accessor :protocol
|
50
50
|
|
51
|
-
def trailers
|
52
|
-
if @headers.respond_to?(:trailers)
|
53
|
-
@headers.trailers
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
51
|
# Send the request to the given connection.
|
58
52
|
def call(connection)
|
59
53
|
connection.call(self)
|
@@ -28,7 +28,7 @@ module Protocol
|
|
28
28
|
class Response
|
29
29
|
prepend Body::Reader
|
30
30
|
|
31
|
-
def initialize(version = nil, status = 200, headers =
|
31
|
+
def initialize(version = nil, status = 200, headers = Headers.new, body = nil, protocol = nil)
|
32
32
|
@version = version
|
33
33
|
@status = status
|
34
34
|
@headers = headers
|
@@ -42,12 +42,6 @@ module Protocol
|
|
42
42
|
attr_accessor :body
|
43
43
|
attr_accessor :protocol
|
44
44
|
|
45
|
-
def trailers
|
46
|
-
if @headers.respond_to?(:trailers)
|
47
|
-
@headers.trailers
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
45
|
def hijack?
|
52
46
|
false
|
53
47
|
end
|
@@ -88,7 +82,7 @@ module Protocol
|
|
88
82
|
@status == 500
|
89
83
|
end
|
90
84
|
|
91
|
-
def self.[](status, headers =
|
85
|
+
def self.[](status, headers = nil, body = nil, protocol = nil)
|
92
86
|
body = Body::Buffered.wrap(body)
|
93
87
|
headers = ::Protocol::HTTP::Headers[headers]
|
94
88
|
|
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.18.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-04-
|
11
|
+
date: 2020-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: covered
|