async-http 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/async-http.gemspec +1 -1
- data/lib/async/http/accept_encoding.rb +65 -0
- data/lib/async/http/body.rb +2 -244
- data/lib/async/http/body/buffered.rb +107 -0
- data/lib/async/http/body/chunked.rb +67 -0
- data/lib/async/http/body/deflate.rb +106 -0
- data/lib/async/http/body/fixed.rb +83 -0
- data/lib/async/http/body/inflate.rb +55 -0
- data/lib/async/http/body/readable.rb +73 -0
- data/lib/async/http/body/streamable.rb +52 -0
- data/lib/async/http/body/wrapper.rb +58 -0
- data/lib/async/http/body/writable.rb +81 -0
- data/lib/async/http/client.rb +14 -19
- data/lib/async/http/content_encoding.rb +71 -0
- data/lib/async/http/middleware.rb +55 -0
- data/lib/async/http/middleware/builder.rb +50 -0
- data/lib/async/http/protocol/http10.rb +13 -11
- data/lib/async/http/protocol/http11.rb +24 -14
- data/lib/async/http/protocol/http2.rb +62 -48
- data/lib/async/http/reference.rb +173 -0
- data/lib/async/http/relative_location.rb +75 -0
- data/lib/async/http/request.rb +8 -2
- data/lib/async/http/response.rb +12 -2
- data/lib/async/http/server.rb +4 -2
- data/lib/async/http/statistics.rb +131 -0
- data/lib/async/http/url_endpoint.rb +17 -1
- data/lib/async/http/version.rb +1 -1
- metadata +20 -5
- data/lib/async/http/deflate_body.rb +0 -124
@@ -28,12 +28,16 @@ module Async
|
|
28
28
|
module HTTP
|
29
29
|
class URLEndpoint < Async::IO::Endpoint
|
30
30
|
def self.parse(string, **options)
|
31
|
-
|
31
|
+
url = URI.parse(string).normalize
|
32
|
+
|
33
|
+
self.new(url, **options)
|
32
34
|
end
|
33
35
|
|
34
36
|
def initialize(url, endpoint = nil, **options)
|
35
37
|
super(**options)
|
36
38
|
|
39
|
+
raise ArgumentError.new("URL must be absolute (include scheme, host): #{url}") unless url.absolute?
|
40
|
+
|
37
41
|
@url = url
|
38
42
|
@endpoint = endpoint
|
39
43
|
end
|
@@ -120,6 +124,18 @@ module Async
|
|
120
124
|
yield self.class.new(@url, endpoint, @options)
|
121
125
|
end
|
122
126
|
end
|
127
|
+
|
128
|
+
def key
|
129
|
+
[@url.scheme, @url.userinfo, @url.host, @url.port, @options]
|
130
|
+
end
|
131
|
+
|
132
|
+
def eql? other
|
133
|
+
self.key.eql? other.key
|
134
|
+
end
|
135
|
+
|
136
|
+
def hash
|
137
|
+
self.key.hash
|
138
|
+
end
|
123
139
|
end
|
124
140
|
end
|
125
141
|
end
|
data/lib/async/http/version.rb
CHANGED
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.
|
4
|
+
version: 0.19.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-04-
|
11
|
+
date: 2018-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: async-io
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,9 +123,21 @@ files:
|
|
123
123
|
- Rakefile
|
124
124
|
- async-http.gemspec
|
125
125
|
- lib/async/http.rb
|
126
|
+
- lib/async/http/accept_encoding.rb
|
126
127
|
- lib/async/http/body.rb
|
128
|
+
- lib/async/http/body/buffered.rb
|
129
|
+
- lib/async/http/body/chunked.rb
|
130
|
+
- lib/async/http/body/deflate.rb
|
131
|
+
- lib/async/http/body/fixed.rb
|
132
|
+
- lib/async/http/body/inflate.rb
|
133
|
+
- lib/async/http/body/readable.rb
|
134
|
+
- lib/async/http/body/streamable.rb
|
135
|
+
- lib/async/http/body/wrapper.rb
|
136
|
+
- lib/async/http/body/writable.rb
|
127
137
|
- lib/async/http/client.rb
|
128
|
-
- lib/async/http/
|
138
|
+
- lib/async/http/content_encoding.rb
|
139
|
+
- lib/async/http/middleware.rb
|
140
|
+
- lib/async/http/middleware/builder.rb
|
129
141
|
- lib/async/http/pool.rb
|
130
142
|
- lib/async/http/protocol.rb
|
131
143
|
- lib/async/http/protocol/http1.rb
|
@@ -133,9 +145,12 @@ files:
|
|
133
145
|
- lib/async/http/protocol/http11.rb
|
134
146
|
- lib/async/http/protocol/http2.rb
|
135
147
|
- lib/async/http/protocol/https.rb
|
148
|
+
- lib/async/http/reference.rb
|
149
|
+
- lib/async/http/relative_location.rb
|
136
150
|
- lib/async/http/request.rb
|
137
151
|
- lib/async/http/response.rb
|
138
152
|
- lib/async/http/server.rb
|
153
|
+
- lib/async/http/statistics.rb
|
139
154
|
- lib/async/http/url_endpoint.rb
|
140
155
|
- lib/async/http/version.rb
|
141
156
|
homepage: https://github.com/socketry/async-http
|
@@ -1,124 +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
|
-
module Async
|
24
|
-
module HTTP
|
25
|
-
class DeflateBody
|
26
|
-
DEFLATE = -Zlib::MAX_WBITS
|
27
|
-
GZIP = Zlib::MAX_WBITS | 16
|
28
|
-
|
29
|
-
ENCODINGS = {
|
30
|
-
'deflate' => DEFLATE,
|
31
|
-
'gzip' => GZIP,
|
32
|
-
}
|
33
|
-
|
34
|
-
def self.for_request(headers, body, *args)
|
35
|
-
if content_encoding = headers['content-encoding']
|
36
|
-
if encoding = ENCODINGS[content_encoding]
|
37
|
-
return self.for(body, encoding, *args)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
return body
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.for(body, encoding = GZIP, level = Zlib::DEFAULT_COMPRESSION)
|
45
|
-
self.new(body, Zlib::Deflate.new(level, encoding))
|
46
|
-
end
|
47
|
-
|
48
|
-
def initialize(body, stream)
|
49
|
-
@body = body
|
50
|
-
@stream = stream
|
51
|
-
end
|
52
|
-
|
53
|
-
def each(&block)
|
54
|
-
return to_enum unless block_given?
|
55
|
-
|
56
|
-
while chunk = self.read
|
57
|
-
yield chunk
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def read
|
62
|
-
return if @stream.finished?
|
63
|
-
|
64
|
-
if chunk = @body.read
|
65
|
-
return @stream.deflate(chunk, Zlib::SYNC_FLUSH)
|
66
|
-
else
|
67
|
-
chunk = @stream.finish
|
68
|
-
|
69
|
-
return chunk.empty? ? nil : chunk
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def close
|
74
|
-
@body = @body.close
|
75
|
-
|
76
|
-
return self
|
77
|
-
end
|
78
|
-
|
79
|
-
def join
|
80
|
-
buffer = Async::IO::BinaryString.new
|
81
|
-
|
82
|
-
while chunk = self.read
|
83
|
-
buffer << chunk
|
84
|
-
end
|
85
|
-
|
86
|
-
return buffer
|
87
|
-
end
|
88
|
-
|
89
|
-
def finished?
|
90
|
-
@body.finished?
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
class InflateBody < DeflateBody
|
95
|
-
def self.for_response(response)
|
96
|
-
if content_encoding = response.headers['content-encoding']
|
97
|
-
if encoding = ENCODINGS[content_encoding]
|
98
|
-
return self.for(response.body, encoding)
|
99
|
-
end
|
100
|
-
|
101
|
-
raise ArgumentError.new("Unsupported content encoding: #{content_encoding.inspect}")
|
102
|
-
end
|
103
|
-
|
104
|
-
return response.body
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.for(body, encoding = GZIP)
|
108
|
-
self.new(body, Zlib::Inflate.new(encoding))
|
109
|
-
end
|
110
|
-
|
111
|
-
def read
|
112
|
-
return if @stream.finished?
|
113
|
-
|
114
|
-
if chunk = @body.read
|
115
|
-
chunk = @stream.inflate(chunk)
|
116
|
-
else
|
117
|
-
chunk = @stream.finish
|
118
|
-
end
|
119
|
-
|
120
|
-
return chunk.empty? ? nil : chunk
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|