async-http 0.40.3 → 0.41.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/async-http.gemspec +3 -3
  4. data/examples/request.rb +3 -3
  5. data/examples/upload/client.rb +2 -2
  6. data/examples/upload/server.rb +3 -3
  7. data/lib/async/http.rb +1 -1
  8. data/lib/async/http/body.rb +2 -11
  9. data/lib/async/http/body/hijack.rb +3 -3
  10. data/lib/async/http/body/writable.rb +3 -2
  11. data/lib/async/http/client.rb +11 -10
  12. data/lib/async/http/{url_endpoint.rb → endpoint.rb} +1 -1
  13. data/lib/async/http/internet.rb +6 -6
  14. data/lib/async/http/pool.rb +1 -1
  15. data/lib/async/http/protocol/http1/client.rb +19 -8
  16. data/lib/async/http/protocol/http1/connection.rb +8 -25
  17. data/lib/async/http/protocol/http1/request.rb +10 -7
  18. data/lib/async/http/protocol/http1/response.rb +19 -3
  19. data/lib/async/http/protocol/http1/server.rb +14 -2
  20. data/lib/async/http/protocol/http10.rb +4 -0
  21. data/lib/async/http/protocol/http11.rb +4 -0
  22. data/lib/async/http/protocol/http2.rb +8 -0
  23. data/lib/async/http/protocol/http2/connection.rb +11 -2
  24. data/lib/async/http/protocol/http2/promise.rb +2 -2
  25. data/lib/async/http/protocol/http2/request.rb +17 -9
  26. data/lib/async/http/protocol/http2/response.rb +12 -6
  27. data/lib/async/http/protocol/http2/server.rb +12 -10
  28. data/lib/async/http/protocol/http2/stream.rb +1 -1
  29. data/lib/async/http/protocol/request.rb +6 -6
  30. data/lib/async/http/protocol/response.rb +5 -6
  31. data/lib/async/http/relative_location.rb +5 -4
  32. data/lib/async/http/server.rb +7 -5
  33. data/lib/async/http/statistics.rb +2 -2
  34. data/lib/async/http/version.rb +1 -1
  35. data/tasks/server.rake +4 -4
  36. metadata +10 -29
  37. data/lib/async/http/accept_encoding.rb +0 -65
  38. data/lib/async/http/body/buffered.rb +0 -89
  39. data/lib/async/http/body/chunked.rb +0 -76
  40. data/lib/async/http/body/deflate.rb +0 -113
  41. data/lib/async/http/body/file.rb +0 -98
  42. data/lib/async/http/body/fixed.rb +0 -72
  43. data/lib/async/http/body/inflate.rb +0 -59
  44. data/lib/async/http/body/readable.rb +0 -76
  45. data/lib/async/http/body/reader.rb +0 -83
  46. data/lib/async/http/body/remainder.rb +0 -56
  47. data/lib/async/http/body/rewindable.rb +0 -60
  48. data/lib/async/http/body/streamable.rb +0 -83
  49. data/lib/async/http/body/wrapper.rb +0 -65
  50. data/lib/async/http/content_encoding.rb +0 -76
  51. data/lib/async/http/headers.rb +0 -27
  52. data/lib/async/http/middleware.rb +0 -79
  53. data/lib/async/http/middleware/builder.rb +0 -61
  54. data/lib/async/http/request.rb +0 -71
  55. data/lib/async/http/response.rb +0 -90
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.40.3
4
+ version: 0.41.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: 2019-05-13 00:00:00.000000000 Z
11
+ date: 2019-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -44,42 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: 0.5.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.3.0
54
+ version: 0.5.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: protocol-http1
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.5.0
61
+ version: 0.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.5.0
68
+ version: 0.6.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: protocol-http2
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.0
75
+ version: 0.3.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.0
82
+ version: 0.3.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: async-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -179,31 +179,15 @@ files:
179
179
  - examples/upload/server.rb
180
180
  - examples/upload/upload.rb
181
181
  - lib/async/http.rb
182
- - lib/async/http/accept_encoding.rb
183
182
  - lib/async/http/body.rb
184
- - lib/async/http/body/buffered.rb
185
- - lib/async/http/body/chunked.rb
186
- - lib/async/http/body/deflate.rb
187
183
  - lib/async/http/body/delayed.rb
188
- - lib/async/http/body/file.rb
189
- - lib/async/http/body/fixed.rb
190
184
  - lib/async/http/body/hijack.rb
191
- - lib/async/http/body/inflate.rb
192
- - lib/async/http/body/readable.rb
193
- - lib/async/http/body/reader.rb
194
- - lib/async/http/body/remainder.rb
195
- - lib/async/http/body/rewindable.rb
196
185
  - lib/async/http/body/slowloris.rb
197
186
  - lib/async/http/body/stream.rb
198
- - lib/async/http/body/streamable.rb
199
- - lib/async/http/body/wrapper.rb
200
187
  - lib/async/http/body/writable.rb
201
188
  - lib/async/http/client.rb
202
- - lib/async/http/content_encoding.rb
203
- - lib/async/http/headers.rb
189
+ - lib/async/http/endpoint.rb
204
190
  - lib/async/http/internet.rb
205
- - lib/async/http/middleware.rb
206
- - lib/async/http/middleware/builder.rb
207
191
  - lib/async/http/pool.rb
208
192
  - lib/async/http/protocol.rb
209
193
  - lib/async/http/protocol/http1.rb
@@ -227,11 +211,8 @@ files:
227
211
  - lib/async/http/protocol/response.rb
228
212
  - lib/async/http/reference.rb
229
213
  - lib/async/http/relative_location.rb
230
- - lib/async/http/request.rb
231
- - lib/async/http/response.rb
232
214
  - lib/async/http/server.rb
233
215
  - lib/async/http/statistics.rb
234
- - lib/async/http/url_endpoint.rb
235
216
  - lib/async/http/version.rb
236
217
  - tasks/server.rake
237
218
  homepage: https://github.com/socketry/async-http
@@ -252,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
233
  - !ruby/object:Gem::Version
253
234
  version: '0'
254
235
  requirements: []
255
- rubygems_version: 3.0.3
236
+ rubygems_version: 3.0.2
256
237
  signing_key:
257
238
  specification_version: 4
258
239
  summary: A HTTP client and server library.
@@ -1,65 +0,0 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'middleware'
22
-
23
- require_relative 'body/buffered'
24
- require_relative 'body/inflate'
25
-
26
- module Async
27
- module HTTP
28
- # Set a valid accept-encoding header and decode the response.
29
- class AcceptEncoding < Middleware
30
- ACCEPT_ENCODING = 'accept-encoding'.freeze
31
- CONTENT_ENCODING = 'content-encoding'.freeze
32
-
33
- DEFAULT_WRAPPERS = {
34
- 'gzip' => Body::Inflate.method(:for),
35
- 'identity' => ->(body){body},
36
- }
37
-
38
- def initialize(app, wrappers = DEFAULT_WRAPPERS)
39
- super(app)
40
-
41
- @accept_encoding = wrappers.keys.join(', ')
42
- @wrappers = wrappers
43
- end
44
-
45
- def call(request)
46
- request.headers[ACCEPT_ENCODING] = @accept_encoding
47
-
48
- response = super
49
-
50
- if body = response.body and !body.empty? and content_encoding = response.headers.delete(CONTENT_ENCODING)
51
- # We want to unwrap all encodings
52
- content_encoding.reverse_each do |name|
53
- if wrapper = @wrappers[name]
54
- body = wrapper.call(body)
55
- end
56
- end
57
-
58
- response.body = body
59
- end
60
-
61
- return response
62
- end
63
- end
64
- end
65
- end
@@ -1,89 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'readable'
22
-
23
- module Async
24
- module HTTP
25
- module Body
26
- # A body which buffers all it's contents.
27
- class Buffered < Readable
28
- # Wraps an array into a buffered body.
29
- # @return [Readable, nil] the wrapped body or nil if nil was given.
30
- def self.wrap(body)
31
- if body.is_a? Async::HTTP::Body::Readable
32
- return body
33
- elsif body.is_a? Array
34
- return self.new(body)
35
- elsif body.is_a?(String)
36
- return self.new([body])
37
- elsif body
38
- return self.for(body)
39
- end
40
- end
41
-
42
- def self.for(body)
43
- chunks = []
44
-
45
- body.each do |chunk|
46
- chunks << chunk
47
- end
48
-
49
- self.new(chunks)
50
- end
51
-
52
- def initialize(chunks, length = nil)
53
- @chunks = chunks
54
- @length = length
55
-
56
- @index = 0
57
- end
58
-
59
- def finish
60
- self
61
- end
62
-
63
- def length
64
- @length ||= @chunks.inject(0) {|sum, chunk| sum + chunk.bytesize}
65
- end
66
-
67
- def empty?
68
- @index >= @chunks.length
69
- end
70
-
71
- def read
72
- if chunk = @chunks[@index]
73
- @index += 1
74
- end
75
-
76
- return chunk&.dup
77
- end
78
-
79
- def rewind
80
- @index = 0
81
- end
82
-
83
- def inspect
84
- "\#<#{self.class} #{@chunks.count} chunks, #{self.length} bytes>"
85
- end
86
- end
87
- end
88
- end
89
- end
@@ -1,76 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'readable'
22
-
23
- module Async
24
- module HTTP
25
- module Body
26
- class Chunked < Readable
27
- def initialize(protocol)
28
- @protocol = protocol
29
- @finished = false
30
-
31
- @length = 0
32
- @count = 0
33
- end
34
-
35
- def empty?
36
- @finished
37
- end
38
-
39
- def close(error = nil)
40
- # We only close the connection if we haven't completed reading the entire body:
41
- unless @finished
42
- @protocol.close
43
- @finished = true
44
- end
45
-
46
- super
47
- end
48
-
49
- def read
50
- return nil if @finished
51
-
52
- length = @protocol.read_line.to_i(16)
53
-
54
- if length == 0
55
- @finished = true
56
- @protocol.read_line
57
-
58
- return nil
59
- end
60
-
61
- chunk = @protocol.stream.read(length)
62
- @protocol.read_line # Consume the trailing CRLF
63
-
64
- @length += length
65
- @count += 1
66
-
67
- return chunk
68
- end
69
-
70
- def inspect
71
- "\#<#{self.class} #{@length} bytes read in #{@count} chunks>"
72
- end
73
- end
74
- end
75
- end
76
- end
@@ -1,113 +0,0 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require_relative 'wrapper'
22
-
23
- require 'zlib'
24
-
25
- module Async
26
- module HTTP
27
- module Body
28
- class ZStream < Wrapper
29
- DEFAULT_LEVEL = 7
30
-
31
- DEFLATE = -Zlib::MAX_WBITS
32
- GZIP = Zlib::MAX_WBITS | 16
33
-
34
- ENCODINGS = {
35
- 'deflate' => DEFLATE,
36
- 'gzip' => GZIP,
37
- }
38
-
39
- def self.encoding_name(window_size)
40
- if window_size <= -8
41
- return 'deflate'
42
- elsif window_size >= 16
43
- return 'gzip'
44
- else
45
- return 'compress'
46
- end
47
- end
48
-
49
- def initialize(body, stream)
50
- super(body)
51
-
52
- @stream = stream
53
-
54
- @input_length = 0
55
- @output_length = 0
56
- end
57
-
58
- def close(error = nil)
59
- @stream.close unless @stream.closed?
60
-
61
- super
62
- end
63
-
64
- def length
65
- # We don't know the length of the output until after it's been compressed.
66
- nil
67
- end
68
-
69
- attr :input_length
70
- attr :output_length
71
-
72
- def ratio
73
- if @input_length != 0
74
- @output_length.to_f / @input_length.to_f
75
- else
76
- 1.0
77
- end
78
- end
79
-
80
- def inspect
81
- "#{super} | \#<#{self.class} #{(ratio*100).round(2)}%>"
82
- end
83
- end
84
-
85
- class Deflate < ZStream
86
- def self.for(body, window_size = GZIP, level = DEFAULT_LEVEL)
87
- self.new(body, Zlib::Deflate.new(level, window_size))
88
- end
89
-
90
- def read
91
- return if @stream.finished?
92
-
93
- # The stream might have been closed while waiting for the chunk to come in.
94
- if chunk = super
95
- @input_length += chunk.bytesize
96
-
97
- chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
98
-
99
- @output_length += chunk.bytesize
100
-
101
- return chunk
102
- elsif !@stream.closed?
103
- chunk = @stream.finish
104
-
105
- @output_length += chunk.bytesize
106
-
107
- return chunk.empty? ? nil : chunk
108
- end
109
- end
110
- end
111
- end
112
- end
113
- end