async-http 0.30.4 → 0.31.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/async-http.gemspec +2 -2
- data/lib/async/http/body/file.rb +1 -0
- data/lib/async/http/client.rb +1 -0
- data/lib/async/http/pool.rb +2 -2
- data/lib/async/http/protocol.rb +24 -0
- data/lib/async/http/protocol/http1.rb +19 -28
- data/lib/async/http/protocol/http1/client.rb +55 -0
- data/lib/async/http/protocol/http1/connection.rb +94 -0
- data/lib/async/http/protocol/http1/request.rb +45 -0
- data/lib/async/http/protocol/http1/response.rb +37 -0
- data/lib/async/http/protocol/http1/server.rb +72 -0
- data/lib/async/http/protocol/http10.rb +9 -24
- data/lib/async/http/protocol/http10/client.rb +36 -0
- data/lib/async/http/protocol/http10/server.rb +36 -0
- data/lib/async/http/protocol/http11.rb +9 -405
- data/lib/async/http/protocol/http11/client.rb +36 -0
- data/lib/async/http/protocol/http11/server.rb +36 -0
- data/lib/async/http/protocol/http2/client.rb +1 -0
- data/lib/async/http/protocol/http2/connection.rb +1 -1
- data/lib/async/http/protocol/http2/request.rb +1 -1
- data/lib/async/http/protocol/http2/server.rb +2 -1
- data/lib/async/http/reference.rb +4 -165
- data/lib/async/http/server.rb +1 -2
- data/lib/async/http/version.rb +1 -1
- metadata +16 -7
@@ -0,0 +1,36 @@
|
|
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 'http/protocol/http11/connection'
|
22
|
+
|
23
|
+
require_relative '../http1/connection'
|
24
|
+
require_relative '../http1/client'
|
25
|
+
|
26
|
+
module Async
|
27
|
+
module HTTP
|
28
|
+
module Protocol
|
29
|
+
module HTTP11
|
30
|
+
class Client < ::HTTP::Protocol::HTTP11::Connection
|
31
|
+
include HTTP1::Connection, HTTP1::Client
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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 'http/protocol/http11/connection'
|
22
|
+
|
23
|
+
require_relative '../http1/connection'
|
24
|
+
require_relative '../http1/server'
|
25
|
+
|
26
|
+
module Async
|
27
|
+
module HTTP
|
28
|
+
module Protocol
|
29
|
+
module HTTP11
|
30
|
+
class Server < ::HTTP::Protocol::HTTP11::Connection
|
31
|
+
include HTTP1::Connection, HTTP1::Server
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -34,6 +34,7 @@ module Async
|
|
34
34
|
@stream = stream
|
35
35
|
|
36
36
|
framer = ::HTTP::Protocol::HTTP2::Framer.new(stream)
|
37
|
+
|
37
38
|
super(framer, *args)
|
38
39
|
|
39
40
|
@requests = Async::Queue.new
|
@@ -53,7 +54,7 @@ module Async
|
|
53
54
|
@requests.enqueue nil
|
54
55
|
end
|
55
56
|
|
56
|
-
def
|
57
|
+
def each
|
57
58
|
while request = @requests.dequeue
|
58
59
|
@count += 1
|
59
60
|
|
data/lib/async/http/reference.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright,
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -18,171 +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/reference'
|
22
|
+
|
21
23
|
module Async
|
22
24
|
module HTTP
|
23
|
-
|
24
|
-
class Reference
|
25
|
-
def initialize(path, query_string, fragment, parameters)
|
26
|
-
@path = path
|
27
|
-
@query_string = query_string
|
28
|
-
@fragment = fragment
|
29
|
-
@parameters = parameters
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.[] reference
|
33
|
-
if reference.is_a? self
|
34
|
-
return reference
|
35
|
-
else
|
36
|
-
return self.parse(reference)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Generate a reference from a path and user parameters. The path may contain a `#fragment` or `?query=parameters`.
|
41
|
-
def self.parse(path = '/', parameters = nil)
|
42
|
-
base, fragment = path.split('#', 2)
|
43
|
-
path, query_string = base.split('?', 2)
|
44
|
-
|
45
|
-
self.new(path, query_string, fragment, parameters)
|
46
|
-
end
|
47
|
-
|
48
|
-
# The path component, e.g. /foo/bar/index.html
|
49
|
-
attr :path
|
50
|
-
|
51
|
-
# The un-parsed query string, e.g. 'x=10&y=20'
|
52
|
-
attr :query_string
|
53
|
-
|
54
|
-
# A fragment, the part after the '#'
|
55
|
-
attr :fragment
|
56
|
-
|
57
|
-
# User supplied parameters that will be appended to the query part.
|
58
|
-
attr :parameters
|
59
|
-
|
60
|
-
def parameters?
|
61
|
-
@parameters and !@parameters.empty?
|
62
|
-
end
|
63
|
-
|
64
|
-
def query_string?
|
65
|
-
@query_string and !@query_string.empty?
|
66
|
-
end
|
67
|
-
|
68
|
-
def fragment?
|
69
|
-
@fragment and !@fragment.empty?
|
70
|
-
end
|
71
|
-
|
72
|
-
def append(buffer)
|
73
|
-
if query_string?
|
74
|
-
buffer << escape_path(@path) << '?' << @query_string
|
75
|
-
buffer << '&' << encode(@parameters) if parameters?
|
76
|
-
else
|
77
|
-
buffer << escape_path(@path)
|
78
|
-
buffer << '?' << encode(@parameters) if parameters?
|
79
|
-
end
|
80
|
-
|
81
|
-
if fragment?
|
82
|
-
buffer << '#' << escape(@fragment)
|
83
|
-
end
|
84
|
-
|
85
|
-
return buffer
|
86
|
-
end
|
87
|
-
|
88
|
-
def to_str
|
89
|
-
append(String.new)
|
90
|
-
end
|
91
|
-
|
92
|
-
alias to_s to_str
|
93
|
-
|
94
|
-
def + other
|
95
|
-
other = self.class[other]
|
96
|
-
|
97
|
-
self.class.new(
|
98
|
-
expand_path(self.path, other.path),
|
99
|
-
other.query_string,
|
100
|
-
other.fragment,
|
101
|
-
other.parameters,
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
def [] parameters
|
106
|
-
self.dup(nil, parameters)
|
107
|
-
end
|
108
|
-
|
109
|
-
def dup(path = nil, parameters = nil)
|
110
|
-
if @parameters
|
111
|
-
if parameters
|
112
|
-
parameters = @parameters.merge(parameters)
|
113
|
-
else
|
114
|
-
parameters = @parameters
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
if path
|
119
|
-
path = @path + '/' + path
|
120
|
-
else
|
121
|
-
path = @path
|
122
|
-
end
|
123
|
-
|
124
|
-
self.class.new(path, @query_string, @fragment, parameters)
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
def expand_path(base, relative)
|
130
|
-
if relative.start_with? '/'
|
131
|
-
return relative
|
132
|
-
else
|
133
|
-
path = base.split('/')
|
134
|
-
parts = relative.split('/')
|
135
|
-
|
136
|
-
parts.each do |part|
|
137
|
-
if part == '..'
|
138
|
-
path.pop
|
139
|
-
else
|
140
|
-
path << part
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
return path.join('/')
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
# Escapes a generic string, using percent encoding.
|
149
|
-
def escape(string)
|
150
|
-
encoding = string.encoding
|
151
|
-
string.b.gsub(/([^a-zA-Z0-9_.\-]+)/) do |m|
|
152
|
-
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
153
|
-
end.force_encoding(encoding)
|
154
|
-
end
|
155
|
-
|
156
|
-
# According to https://tools.ietf.org/html/rfc3986#section-3.3, we escape non-pchar.
|
157
|
-
NON_PCHAR = /([^a-zA-Z0-9_\-\.~!$&'()*+,;=:@\/]+)/.freeze
|
158
|
-
|
159
|
-
# Escapes a path
|
160
|
-
def escape_path(path)
|
161
|
-
encoding = path.encoding
|
162
|
-
path.b.gsub(NON_PCHAR) do |m|
|
163
|
-
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
164
|
-
end.force_encoding(encoding)
|
165
|
-
end
|
166
|
-
|
167
|
-
# Encodes a hash or array into a query string
|
168
|
-
def encode(value, prefix = nil)
|
169
|
-
case value
|
170
|
-
when Array
|
171
|
-
return value.map {|v|
|
172
|
-
encode(v, "#{prefix}[]")
|
173
|
-
}.join("&")
|
174
|
-
when Hash
|
175
|
-
return value.map {|k, v|
|
176
|
-
encode(v, prefix ? "#{prefix}[#{escape(k.to_s)}]" : escape(k.to_s))
|
177
|
-
}.reject(&:empty?).join('&')
|
178
|
-
when nil
|
179
|
-
return prefix
|
180
|
-
else
|
181
|
-
raise ArgumentError, "value must be a Hash" if prefix.nil?
|
182
|
-
|
183
|
-
return "#{prefix}=#{escape(value.to_s)}"
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
25
|
+
Reference = ::HTTP::Protocol::Reference
|
187
26
|
end
|
188
27
|
end
|
data/lib/async/http/server.rb
CHANGED
@@ -23,7 +23,6 @@ require 'async/io/endpoint'
|
|
23
23
|
require_relative 'protocol'
|
24
24
|
require_relative 'response'
|
25
25
|
|
26
|
-
|
27
26
|
module Async
|
28
27
|
module HTTP
|
29
28
|
class Server < Middleware
|
@@ -46,7 +45,7 @@ module Async
|
|
46
45
|
|
47
46
|
Async.logger.debug(self) {"Incoming connnection from #{address.inspect} to #{protocol}"}
|
48
47
|
|
49
|
-
protocol.
|
48
|
+
protocol.each do |request|
|
50
49
|
request.remote_address = address
|
51
50
|
# Async.logger.debug(self) {"Incoming request from #{address.inspect}: #{request.method} #{request.path}"}
|
52
51
|
|
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.31.1
|
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-
|
11
|
+
date: 2018-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.16'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.16'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: http-protocol
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 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.
|
54
|
+
version: 0.5.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: async-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,8 +159,17 @@ files:
|
|
159
159
|
- lib/async/http/pool.rb
|
160
160
|
- lib/async/http/protocol.rb
|
161
161
|
- lib/async/http/protocol/http1.rb
|
162
|
+
- lib/async/http/protocol/http1/client.rb
|
163
|
+
- lib/async/http/protocol/http1/connection.rb
|
164
|
+
- lib/async/http/protocol/http1/request.rb
|
165
|
+
- lib/async/http/protocol/http1/response.rb
|
166
|
+
- lib/async/http/protocol/http1/server.rb
|
162
167
|
- lib/async/http/protocol/http10.rb
|
168
|
+
- lib/async/http/protocol/http10/client.rb
|
169
|
+
- lib/async/http/protocol/http10/server.rb
|
163
170
|
- lib/async/http/protocol/http11.rb
|
171
|
+
- lib/async/http/protocol/http11/client.rb
|
172
|
+
- lib/async/http/protocol/http11/server.rb
|
164
173
|
- lib/async/http/protocol/http2.rb
|
165
174
|
- lib/async/http/protocol/http2/client.rb
|
166
175
|
- lib/async/http/protocol/http2/connection.rb
|
@@ -198,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
207
|
version: '0'
|
199
208
|
requirements: []
|
200
209
|
rubyforge_project:
|
201
|
-
rubygems_version: 2.7.
|
210
|
+
rubygems_version: 2.7.7
|
202
211
|
signing_key:
|
203
212
|
specification_version: 4
|
204
213
|
summary: A HTTP client and server library.
|