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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 844a6b761eb8218e0b856cccefc1767cbac8db29ed703d1b8419a532b75bc7bf
4
- data.tar.gz: 85dbf29d8cc3aefdbb79af289c0d8a9e91622f8bf13be6ca552cc7ec49acefb9
3
+ metadata.gz: 81d011054c5b26d9adf2351384897c7eefe52ce45ed056f9593ef6d5beeff716
4
+ data.tar.gz: 1dc681ebfccc93481badc3dc09006f8fb29928ea3f63ee5ef3dc0f90fa0978c6
5
5
  SHA512:
6
- metadata.gz: 8771480a7207e74671a33f05fe21143039b04458c11489c5f6ffa6d8f36e44c7c5193c938bb7ffdb47c024e70a3f7abce5f212225e97131f60ebb665d7127887
7
- data.tar.gz: 16582bbbe013e74ce15db5e2aa61f0f6750bae5e28d43483998d0a9d0b54088ae5ae6771048ca02ff466daab42bc72af96ea7d3d400675d3a09fe6b77699c641
6
+ metadata.gz: 1f2d3ed31be6772e17d9e8f116b41f9682c62e4665a11bf8bd49e180a39f8d8f4a8f267552dc6c0aa0dbac86dd5d06f5bb10e7b4081384d59f57af8b109ea2f3
7
+ data.tar.gz: f98c68034cd663a5f773f32b5cbc058738c9fde4399f4afa4adb92fbfcef8dd8da033522755020567d6fd4774ddf0e2dd9188c4adf39da08f88d658072a3120b
@@ -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
- @fields << [key, value]
130
+ merge_into(@indexed, key.downcase, value)
110
131
 
111
- # It would be good to do some kind of validation here.
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 merge(hash, key, value)
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
- merge(hash, key.downcase, value)
191
+ merge_into(hash, key.downcase, value)
174
192
 
175
193
  hash
176
194
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module HTTP
22
22
  module Protocol
23
- VERSION = "0.8.1"
23
+ VERSION = "0.9.0"
24
24
  end
25
25
  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.8.1
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-29 00:00:00.000000000 Z
11
+ date: 2018-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-hpack