async-http 0.30.2 → 0.30.3

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: a937910aa49ee7d30c1941ac83a39f4f5ba2c5c52beec347b510dffd0ac2b40e
4
- data.tar.gz: 62e34957a999e3e83636f2c00e6f9b6227264f1a7c0d00e69048bf7ff9ceab88
3
+ metadata.gz: 063a701b5810c3425ab42fef84e971b8f0c916c0b4ad55cf305b5385850cc6de
4
+ data.tar.gz: 32daee0cf2ca5a488e6e33308a1b7c9f953feafed4111d1e82b6212790570d6c
5
5
  SHA512:
6
- metadata.gz: 5256304facd1f375f6d668b10361d89262d5c367f50eff8d0c9f5c3d8ab6374a70c51a28997357b45bad40d4bb569d7daf3d7fb2a527a88735a8a10083abe2dc
7
- data.tar.gz: c91d8eef348500108f6186bd80ba79eaaac72af42153f7a00fbb4ea05b6db91196b7b421755fe754e8ae6d05b2c560d6e2d49c172447cd2cbeb8dcd84fc77db8
6
+ metadata.gz: '089514e5e4d794709be2fa407fd8dba4b39e8a3ac309591a238737ad0b267e84c2be525bb6532981c0844a226f6ec5a3433b717bae74e4eb95b10117f0264ec3'
7
+ data.tar.gz: d96035f10d063da6ce0f16086aaa67baaabdd5aec2c733ec8b770af7012bf9b3992060b704e6b8b62f129ef26b92cf246cec1d447386b54cb3bb7cb9c0f81a5d
data/async-http.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency("async", "~> 1.6")
20
20
  spec.add_dependency("async-io", "~> 1.15")
21
21
 
22
- spec.add_dependency("http-protocol", "~> 0.2.0")
22
+ spec.add_dependency("http-protocol", "~> 0.3.0")
23
23
 
24
24
  # spec.add_dependency("openssl")
25
25
 
@@ -18,190 +18,10 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require 'http/protocol/headers'
22
+
21
23
  module Async
22
24
  module HTTP
23
- class Headers
24
- class Split < Array
25
- COMMA = /\s*,\s*/
26
-
27
- def initialize(value)
28
- super(value.split(COMMA))
29
- end
30
-
31
- def << value
32
- super value.split(COMMA)
33
- end
34
-
35
- def to_s
36
- join(", ")
37
- end
38
- end
39
-
40
- class Multiple < Array
41
- def initialize(value)
42
- super()
43
-
44
- self << value
45
- end
46
-
47
- def to_s
48
- join("\n")
49
- end
50
- end
51
-
52
- def self.[] hash
53
- self.new(hash.to_a)
54
- end
55
-
56
- def initialize(fields = [])
57
- @fields = fields
58
- @indexed = to_h
59
- end
60
-
61
- attr :fields
62
-
63
- def freeze
64
- return if frozen?
65
-
66
- @indexed = to_h
67
-
68
- super
69
- end
70
-
71
- def empty?
72
- @fields.empty?
73
- end
74
-
75
- def each(&block)
76
- @fields.each(&block)
77
- end
78
-
79
- def include? key
80
- self[key] != nil
81
- end
82
-
83
- # Delete all headers with the given key, and return the value of the last one, if any.
84
- def delete(key)
85
- values, @fields = @fields.partition do |field|
86
- field.first.downcase == key
87
- end
88
-
89
- if @indexed
90
- @indexed.delete(key)
91
- end
92
-
93
- if field = values.last
94
- return field.last
95
- end
96
- end
97
-
98
- def slice!(keys)
99
- values, @fields = @fields.partition do |field|
100
- keys.include?(field.first.downcase)
101
- end
102
-
103
- if @indexed
104
- keys.each do |key|
105
- @indexed.delete(key)
106
- end
107
- end
108
- end
109
-
110
- def add(key, value)
111
- self[key] = value
112
- end
113
-
114
- def []= key, value
115
- @fields << [key, value]
116
-
117
- if @indexed
118
- # It would be good to do some kind of validation here.
119
- merge(@indexed, key.downcase, value)
120
- end
121
- end
122
-
123
- MERGE_POLICY = {
124
- # Headers which may only be specified once.
125
- 'content-type' => false,
126
- 'content-disposition' => false,
127
- 'content-length' => false,
128
- 'user-agent' => false,
129
- 'referer' => false,
130
- 'host' => false,
131
- 'authorization' => false,
132
- 'proxy-authorization' => false,
133
- 'if-modified-since' => false,
134
- 'if-unmodified-since' => false,
135
- 'from' => false,
136
- 'location' => false,
137
- 'max-forwards' => false,
138
-
139
- 'connection' => Split,
140
-
141
- # Headers specifically for proxies:
142
- 'via' => Split,
143
- 'x-forwarded-for' => Split,
144
-
145
- # Headers which may be specified multiple times, but which can't be concatenated.
146
- 'set-cookie' => Multiple,
147
- 'www-authenticate' => Multiple,
148
- 'proxy-authenticate' => Multiple
149
- }.tap{|hash| hash.default = Split}
150
-
151
- def merge(hash, key, value)
152
- if policy = MERGE_POLICY[key]
153
- if current_value = hash[key]
154
- current_value << value
155
- else
156
- hash[key] = policy.new(value)
157
- end
158
- else
159
- raise ArgumentError, "Header #{key} can only be set once!" if hash.include?(key)
160
-
161
- # We can't merge these, we only expose the last one set.
162
- hash[key] = value
163
- end
164
- end
165
-
166
- def [] key
167
- @indexed ||= to_h
168
-
169
- @indexed[key]
170
- end
171
-
172
- def to_h
173
- @fields.inject({}) do |hash, (key, value)|
174
- merge(hash, key.downcase, value)
175
-
176
- hash
177
- end
178
- end
179
-
180
- def == other
181
- if other.is_a? Hash
182
- to_h == other
183
- else
184
- @fields == other.fields
185
- end
186
- end
187
-
188
- class Merged
189
- def initialize(*all)
190
- @all = all
191
- end
192
-
193
- def << headers
194
- @all << headers
195
- end
196
-
197
- def each(&block)
198
- @all.each do |headers|
199
- headers.each do |key, value|
200
- yield key, value.to_s
201
- end
202
- end
203
- end
204
- end
205
- end
25
+ Headers = ::HTTP::Protocol::Headers
206
26
  end
207
27
  end
@@ -25,14 +25,22 @@ module Async
25
25
  module HTTP
26
26
  module Protocol
27
27
  module HTTP2
28
- DEFAULT_SETTINGS = {
28
+ CLIENT_SETTINGS = {
29
29
  ::HTTP::Protocol::HTTP2::Settings::ENABLE_PUSH => 0,
30
30
  ::HTTP::Protocol::HTTP2::Settings::MAXIMUM_CONCURRENT_STREAMS => 256,
31
31
  ::HTTP::Protocol::HTTP2::Settings::MAXIMUM_FRAME_SIZE => 0x100000,
32
32
  ::HTTP::Protocol::HTTP2::Settings::INITIAL_WINDOW_SIZE => 0x7FFFFFFF,
33
33
  }
34
34
 
35
- def self.client(stream, settings = DEFAULT_SETTINGS)
35
+ SERVER_SETTINGS = {
36
+ ::HTTP::Protocol::HTTP2::Settings::ENABLE_PUSH => 0,
37
+ # We choose a lower maximum concurrent streams to avoid overloading a single connection/thread.
38
+ ::HTTP::Protocol::HTTP2::Settings::MAXIMUM_CONCURRENT_STREAMS => 32,
39
+ ::HTTP::Protocol::HTTP2::Settings::MAXIMUM_FRAME_SIZE => 0x100000,
40
+ ::HTTP::Protocol::HTTP2::Settings::INITIAL_WINDOW_SIZE => 0x7FFFFFFF,
41
+ }
42
+
43
+ def self.client(stream, settings = CLIENT_SETTINGS)
36
44
  client = Client.new(stream)
37
45
 
38
46
  client.send_connection_preface(settings)
@@ -41,7 +49,7 @@ module Async
41
49
  return client
42
50
  end
43
51
 
44
- def self.server(stream, settings = DEFAULT_SETTINGS)
52
+ def self.server(stream, settings = SERVER_SETTINGS)
45
53
  server = Server.new(stream)
46
54
 
47
55
  server.read_connection_preface(settings)
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module HTTP
23
- VERSION = "0.30.2"
23
+ VERSION = "0.30.3"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.2
4
+ version: 0.30.3
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-08-08 00:00:00.000000000 Z
11
+ date: 2018-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: 0.3.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.0
54
+ version: 0.3.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: async-rspec
57
57
  requirement: !ruby/object:Gem::Requirement