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.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/async-http.gemspec +3 -3
- data/examples/request.rb +3 -3
- data/examples/upload/client.rb +2 -2
- data/examples/upload/server.rb +3 -3
- data/lib/async/http.rb +1 -1
- data/lib/async/http/body.rb +2 -11
- data/lib/async/http/body/hijack.rb +3 -3
- data/lib/async/http/body/writable.rb +3 -2
- data/lib/async/http/client.rb +11 -10
- data/lib/async/http/{url_endpoint.rb → endpoint.rb} +1 -1
- data/lib/async/http/internet.rb +6 -6
- data/lib/async/http/pool.rb +1 -1
- data/lib/async/http/protocol/http1/client.rb +19 -8
- data/lib/async/http/protocol/http1/connection.rb +8 -25
- data/lib/async/http/protocol/http1/request.rb +10 -7
- data/lib/async/http/protocol/http1/response.rb +19 -3
- data/lib/async/http/protocol/http1/server.rb +14 -2
- data/lib/async/http/protocol/http10.rb +4 -0
- data/lib/async/http/protocol/http11.rb +4 -0
- data/lib/async/http/protocol/http2.rb +8 -0
- data/lib/async/http/protocol/http2/connection.rb +11 -2
- data/lib/async/http/protocol/http2/promise.rb +2 -2
- data/lib/async/http/protocol/http2/request.rb +17 -9
- data/lib/async/http/protocol/http2/response.rb +12 -6
- data/lib/async/http/protocol/http2/server.rb +12 -10
- data/lib/async/http/protocol/http2/stream.rb +1 -1
- data/lib/async/http/protocol/request.rb +6 -6
- data/lib/async/http/protocol/response.rb +5 -6
- data/lib/async/http/relative_location.rb +5 -4
- data/lib/async/http/server.rb +7 -5
- data/lib/async/http/statistics.rb +2 -2
- data/lib/async/http/version.rb +1 -1
- data/tasks/server.rake +4 -4
- metadata +10 -29
- data/lib/async/http/accept_encoding.rb +0 -65
- data/lib/async/http/body/buffered.rb +0 -89
- data/lib/async/http/body/chunked.rb +0 -76
- data/lib/async/http/body/deflate.rb +0 -113
- data/lib/async/http/body/file.rb +0 -98
- data/lib/async/http/body/fixed.rb +0 -72
- data/lib/async/http/body/inflate.rb +0 -59
- data/lib/async/http/body/readable.rb +0 -76
- data/lib/async/http/body/reader.rb +0 -83
- data/lib/async/http/body/remainder.rb +0 -56
- data/lib/async/http/body/rewindable.rb +0 -60
- data/lib/async/http/body/streamable.rb +0 -83
- data/lib/async/http/body/wrapper.rb +0 -65
- data/lib/async/http/content_encoding.rb +0 -76
- data/lib/async/http/headers.rb +0 -27
- data/lib/async/http/middleware.rb +0 -79
- data/lib/async/http/middleware/builder.rb +0 -61
- data/lib/async/http/request.rb +0 -71
- data/lib/async/http/response.rb +0 -90
data/lib/async/http/body/file.rb
DELETED
@@ -1,98 +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
|
-
require 'async/io/stream'
|
23
|
-
|
24
|
-
module Async
|
25
|
-
module HTTP
|
26
|
-
module Body
|
27
|
-
class File < Readable
|
28
|
-
BLOCK_SIZE = Async::IO::Stream::BLOCK_SIZE
|
29
|
-
MODE = ::File::RDONLY | ::File::BINARY
|
30
|
-
|
31
|
-
def self.open(path, *args)
|
32
|
-
self.new(::File.open(path, MODE), *args)
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(file, range = nil, block_size: BLOCK_SIZE)
|
36
|
-
@file = file
|
37
|
-
|
38
|
-
@block_size = block_size
|
39
|
-
|
40
|
-
if range
|
41
|
-
@file.seek(range.min)
|
42
|
-
@offset = range.min
|
43
|
-
@length = @remaining = range.size
|
44
|
-
else
|
45
|
-
@offset = 0
|
46
|
-
@length = @remaining = @file.size
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def close(error = nil)
|
51
|
-
@file.close
|
52
|
-
@remaining = 0
|
53
|
-
|
54
|
-
super
|
55
|
-
end
|
56
|
-
|
57
|
-
attr :file
|
58
|
-
|
59
|
-
attr :offset
|
60
|
-
attr :length
|
61
|
-
|
62
|
-
def empty?
|
63
|
-
@remaining == 0
|
64
|
-
end
|
65
|
-
|
66
|
-
def rewind
|
67
|
-
@file.seek(@offset)
|
68
|
-
end
|
69
|
-
|
70
|
-
def read
|
71
|
-
if @remaining > 0
|
72
|
-
amount = [@remaining, @block_size].min
|
73
|
-
|
74
|
-
if chunk = @file.read(amount)
|
75
|
-
@remaining -= chunk.bytesize
|
76
|
-
|
77
|
-
return chunk
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def join
|
83
|
-
return "" if @remaining == 0
|
84
|
-
|
85
|
-
buffer = @file.read(@remaining)
|
86
|
-
|
87
|
-
@remaining = 0
|
88
|
-
|
89
|
-
return buffer
|
90
|
-
end
|
91
|
-
|
92
|
-
def inspect
|
93
|
-
"\#<#{self.class} file=#{@file.inspect} offset=#{@offset} remaining=#{@remaining}>"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,72 +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 Fixed < Readable
|
27
|
-
def initialize(stream, length)
|
28
|
-
@stream = stream
|
29
|
-
@length = length
|
30
|
-
@remaining = length
|
31
|
-
end
|
32
|
-
|
33
|
-
attr :length
|
34
|
-
attr :remaining
|
35
|
-
|
36
|
-
def empty?
|
37
|
-
@remaining == 0
|
38
|
-
end
|
39
|
-
|
40
|
-
def close(error = nil)
|
41
|
-
if @remaining != 0
|
42
|
-
@stream.close
|
43
|
-
end
|
44
|
-
|
45
|
-
super
|
46
|
-
end
|
47
|
-
|
48
|
-
def read
|
49
|
-
if @remaining > 0
|
50
|
-
if chunk = @stream.read_partial(@remaining)
|
51
|
-
@remaining -= chunk.bytesize
|
52
|
-
|
53
|
-
return chunk
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def join
|
59
|
-
buffer = @stream.read(@remaining)
|
60
|
-
|
61
|
-
@remaining = 0
|
62
|
-
|
63
|
-
return buffer
|
64
|
-
end
|
65
|
-
|
66
|
-
def inspect
|
67
|
-
"\#<#{self.class} length=#{@length} remaining=#{@remaining}>"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,59 +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 'zlib'
|
22
|
-
|
23
|
-
require_relative 'deflate'
|
24
|
-
|
25
|
-
module Async
|
26
|
-
module HTTP
|
27
|
-
module Body
|
28
|
-
class Inflate < ZStream
|
29
|
-
def self.for(body, encoding = GZIP)
|
30
|
-
self.new(body, Zlib::Inflate.new(encoding))
|
31
|
-
end
|
32
|
-
|
33
|
-
def read
|
34
|
-
return if @stream.finished?
|
35
|
-
|
36
|
-
# The stream might have been closed while waiting for the chunk to come in.
|
37
|
-
if chunk = super
|
38
|
-
@input_length += chunk.bytesize
|
39
|
-
|
40
|
-
# It's possible this triggers the stream to finish.
|
41
|
-
chunk = @stream.inflate(chunk)
|
42
|
-
|
43
|
-
@output_length += chunk.bytesize
|
44
|
-
elsif !@stream.closed?
|
45
|
-
chunk = @stream.finish
|
46
|
-
|
47
|
-
@output_length += chunk.bytesize
|
48
|
-
end
|
49
|
-
|
50
|
-
if chunk.empty? and @stream.finished?
|
51
|
-
return nil
|
52
|
-
end
|
53
|
-
|
54
|
-
return chunk
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
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 'async/io/buffer'
|
22
|
-
|
23
|
-
module Async
|
24
|
-
module HTTP
|
25
|
-
module Body
|
26
|
-
# A generic base class for wrapping body instances. Typically you'd override `#read`.
|
27
|
-
class Readable
|
28
|
-
# The consumer can call stop to signal that the stream output has terminated.
|
29
|
-
def close(error = nil)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Will read return any data?
|
33
|
-
def empty?
|
34
|
-
false
|
35
|
-
end
|
36
|
-
|
37
|
-
def length
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
|
41
|
-
# Read the next available chunk.
|
42
|
-
def read
|
43
|
-
nil
|
44
|
-
end
|
45
|
-
|
46
|
-
# Read all remaining chunks into a buffered body and close the underlying input.
|
47
|
-
def finish
|
48
|
-
# Internally, this invokes `self.each` which then invokes `self.close`.
|
49
|
-
Buffered.for(self)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Enumerate all chunks until finished, then invoke `#close`.
|
53
|
-
def each
|
54
|
-
while chunk = self.read
|
55
|
-
yield chunk
|
56
|
-
# chunk.clear
|
57
|
-
end
|
58
|
-
ensure
|
59
|
-
self.close($!)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Read all remaining chunks into a single binary string using `#each`.
|
63
|
-
def join
|
64
|
-
buffer = IO::Buffer.new
|
65
|
-
|
66
|
-
self.each do |chunk|
|
67
|
-
buffer << chunk
|
68
|
-
chunk.clear
|
69
|
-
end
|
70
|
-
|
71
|
-
return buffer
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,83 +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
|
-
module Async
|
22
|
-
module HTTP
|
23
|
-
module Body
|
24
|
-
# General operations for interacting with a request or response body.
|
25
|
-
module Reader
|
26
|
-
# Read chunks from the body.
|
27
|
-
# @yield [String] read chunks from the body.
|
28
|
-
def each(&block)
|
29
|
-
if @body
|
30
|
-
@body.each(&block)
|
31
|
-
@body = nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Reads the entire request/response body.
|
36
|
-
# @return [String] the entire body as a string.
|
37
|
-
def read
|
38
|
-
if @body
|
39
|
-
buffer = @body.join
|
40
|
-
@body = nil
|
41
|
-
|
42
|
-
return buffer
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Gracefully finish reading the body. This will buffer the remainder of the body.
|
47
|
-
# @return [Buffered] buffers the entire body.
|
48
|
-
def finish
|
49
|
-
if @body
|
50
|
-
body = @body.finish
|
51
|
-
@body = nil
|
52
|
-
|
53
|
-
return body
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Write the body of the response to the given file path.
|
58
|
-
def save(path, mode = ::File::WRONLY|::File::CREAT, *args)
|
59
|
-
if @body
|
60
|
-
::File.open(path, mode, *args) do |file|
|
61
|
-
self.each do |chunk|
|
62
|
-
file.write(chunk)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Close the connection as quickly as possible. Discards body. May close the underlying connection if necessary to terminate the stream.
|
69
|
-
def close(error = nil)
|
70
|
-
if @body
|
71
|
-
@body.close(error)
|
72
|
-
@body = nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Whether there is a body?
|
77
|
-
def body?
|
78
|
-
@body and !@body.empty?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,56 +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 Remainder < Readable
|
27
|
-
def initialize(stream)
|
28
|
-
@stream = stream
|
29
|
-
end
|
30
|
-
|
31
|
-
def empty?
|
32
|
-
@stream.closed?
|
33
|
-
end
|
34
|
-
|
35
|
-
def close(error = nil)
|
36
|
-
# We can't really do anything in this case except close the connection.
|
37
|
-
@stream.close
|
38
|
-
|
39
|
-
super
|
40
|
-
end
|
41
|
-
|
42
|
-
def read
|
43
|
-
@stream.read_partial
|
44
|
-
end
|
45
|
-
|
46
|
-
def join
|
47
|
-
read
|
48
|
-
end
|
49
|
-
|
50
|
-
def inspect
|
51
|
-
"\#<#{self.class} #{@stream.closed? ? 'closed' : 'open'}>"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|