http-protocol 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http/protocol/error.rb +5 -1
- data/lib/http/protocol/headers.rb +25 -7
- data/lib/http/protocol/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: 81d011054c5b26d9adf2351384897c7eefe52ce45ed056f9593ef6d5beeff716
|
4
|
+
data.tar.gz: 1dc681ebfccc93481badc3dc09006f8fb29928ea3f63ee5ef3dc0f90fa0978c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2d3ed31be6772e17d9e8f116b41f9682c62e4665a11bf8bd49e180a39f8d8f4a8f267552dc6c0aa0dbac86dd5d06f5bb10e7b4081384d59f57af8b109ea2f3
|
7
|
+
data.tar.gz: f98c68034cd663a5f773f32b5cbc058738c9fde4399f4afa4adb92fbfcef8dd8da033522755020567d6fd4774ddf0e2dd9188c4adf39da08f88d658072a3120b
|
data/lib/http/protocol/error.rb
CHANGED
@@ -23,7 +23,11 @@ module HTTP
|
|
23
23
|
module Protocol
|
24
24
|
class Error < StandardError
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
# The request was invalid/malformed in some way.
|
28
|
+
class BadRequest < Error
|
29
|
+
end
|
30
|
+
|
27
31
|
# Raised if connection header is missing or invalid indicating that
|
28
32
|
# this is an invalid HTTP 2.0 request - no frames are emitted and the
|
29
33
|
# connection must be aborted.
|
@@ -99,17 +99,37 @@ module HTTP
|
|
99
99
|
keys.each do |key|
|
100
100
|
@indexed.delete(key)
|
101
101
|
end
|
102
|
+
|
103
|
+
return self
|
104
|
+
end
|
105
|
+
|
106
|
+
def slice(keys)
|
107
|
+
self.dup.slice!(keys)
|
102
108
|
end
|
103
109
|
|
104
110
|
def add(key, value)
|
105
111
|
self[key] = value
|
106
112
|
end
|
107
113
|
|
114
|
+
def merge!(headers)
|
115
|
+
headers.each do |key, value|
|
116
|
+
self[key] = value
|
117
|
+
end
|
118
|
+
|
119
|
+
return self
|
120
|
+
end
|
121
|
+
|
122
|
+
def merge(headers)
|
123
|
+
self.dup.merge!(headers)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Append the value to the given key. Some values can be appended multiple times, others can only be set once.
|
127
|
+
# @param key [String] The header key.
|
128
|
+
# @param value The header value.
|
108
129
|
def []= key, value
|
109
|
-
@
|
130
|
+
merge_into(@indexed, key.downcase, value)
|
110
131
|
|
111
|
-
|
112
|
-
merge(@indexed, key.downcase, value)
|
132
|
+
@fields << [key, value]
|
113
133
|
end
|
114
134
|
|
115
135
|
MERGE_POLICY = {
|
@@ -149,7 +169,7 @@ module HTTP
|
|
149
169
|
return @indexed.delete(key)
|
150
170
|
end
|
151
171
|
|
152
|
-
def
|
172
|
+
protected def merge_into(hash, key, value)
|
153
173
|
if policy = MERGE_POLICY[key]
|
154
174
|
if current_value = hash[key]
|
155
175
|
current_value << value
|
@@ -157,8 +177,6 @@ module HTTP
|
|
157
177
|
hash[key] = policy.new(value)
|
158
178
|
end
|
159
179
|
else
|
160
|
-
raise ArgumentError, "Header #{key} can only be set once!" if hash.include?(key)
|
161
|
-
|
162
180
|
# We can't merge these, we only expose the last one set.
|
163
181
|
hash[key] = value
|
164
182
|
end
|
@@ -170,7 +188,7 @@ module HTTP
|
|
170
188
|
|
171
189
|
def to_h
|
172
190
|
@fields.inject({}) do |hash, (key, value)|
|
173
|
-
|
191
|
+
merge_into(hash, key.downcase, value)
|
174
192
|
|
175
193
|
hash
|
176
194
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.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: 2018-10-
|
11
|
+
date: 2018-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http-hpack
|