async-http 0.50.6 → 0.50.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 783c5bea153973dd5a5c01032f4f7b2ec8c838b48508d744bb89c7e77701af6b
4
- data.tar.gz: 688ac155fd0851a35f90cad19235df4c23054d15be47868664aa8c2a26c418ea
3
+ metadata.gz: 7e2b32bb7262cafc68c516d881d6f3a551597248b06b627ae150111dcfa2b656
4
+ data.tar.gz: 63f025a564598ec263413f70b9f4a9561a52d1ebbde4d1b2e66c4c9a5a461b89
5
5
  SHA512:
6
- metadata.gz: 6ff34b8f8ecf007c017e20ea09f5a48564027db9c3f11880d315037ea3d861a82c18651c10c73d9c635595dd575ca21564c1d4679da1cf1dc0c6c78d6875a55f
7
- data.tar.gz: 57ddc6912f594e35243a008782d35d705bd66fbe8f6505b45f28c63268e707f6f9a53f4c009f75bbe75282f690db87a006a8eacc3c49e85086002a6e6e312a9c
6
+ metadata.gz: a2d4dad8cdbf23281345f4ab8e5d7d0b58f83f86513940aa108ba292b82defd2ab5bb23b8fd117618ecc0be1a7ecc1d74a81f65582be18362c5bd7d82072f26f
7
+ data.tar.gz: bef0076a4130b928e1ffd7f42abf15647d639b6ee125de1f71f50d50ae6ede8631f0e11b8c85b455916f3e5417113907de93a9d69e79ac281804d121480c587b
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency("async-io", "~> 1.27.0")
22
22
  spec.add_dependency("async-pool", "~> 0.2")
23
23
 
24
- spec.add_dependency("protocol-http", "~> 0.14.1")
24
+ spec.add_dependency("protocol-http", "~> 0.15.1")
25
25
  spec.add_dependency("protocol-http1", "~> 0.10.0")
26
26
  spec.add_dependency("protocol-http2", "~> 0.11.0")
27
27
 
data/bake.rb ADDED
File without changes
@@ -0,0 +1,44 @@
1
+
2
+ def build
3
+ # Fetch the code:
4
+ system "go get github.com/spf13/cobra"
5
+ system "go get github.com/summerwind/h2spec"
6
+
7
+ # This builds `h2spec` into the current directory
8
+ system "go build ~/go/src/github.com/summerwind/h2spec/cmd/h2spec/h2spec.go"
9
+ end
10
+
11
+ def test
12
+ server do
13
+ system("./h2spec", "-p", "7272")
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def server
20
+ require 'async'
21
+ require 'async/container'
22
+ require 'async/http/server'
23
+ require 'async/io/host_endpoint'
24
+
25
+ endpoint = Async::IO::Endpoint.tcp('127.0.0.1', 7272)
26
+
27
+ container = Async::Container.new
28
+
29
+ Async.logger.info(self){"Starting server..."}
30
+
31
+ container.run(count: 1) do
32
+ server = Async::HTTP::Server.for(endpoint, Async::HTTP::Protocol::HTTP2, "https") do |request|
33
+ Protocol::HTTP::Response[200, {'content-type' => 'text/plain'}, ["Hello World"]]
34
+ end
35
+
36
+ Async do
37
+ server.run
38
+ end
39
+ end
40
+
41
+ yield if block_given?
42
+ ensure
43
+ container&.stop
44
+ end
@@ -165,36 +165,31 @@ module Async
165
165
 
166
166
  def send_response(response)
167
167
  if response.nil?
168
- @stream.send_headers(nil, NO_RESPONSE, ::Protocol::HTTP2::END_STREAM)
169
- elsif response.body? && !self.head?
170
- pseudo_headers = [
171
- [STATUS, response.status],
172
- ]
173
-
174
- if protocol = response.protocol
175
- pseudo_headers << [PROTOCOL, protocol]
176
- end
177
-
178
- if length = response.body.length
179
- pseudo_headers << [CONTENT_LENGTH, length]
180
- end
181
-
182
- headers = ::Protocol::HTTP::Headers::Merged.new(
183
- pseudo_headers,
184
- response.headers
185
- )
186
-
168
+ return @stream.send_headers(nil, NO_RESPONSE, ::Protocol::HTTP2::END_STREAM)
169
+ end
170
+
171
+ protocol_headers = [
172
+ [STATUS, response.status],
173
+ ]
174
+
175
+ if protocol = response.protocol
176
+ protocol_headers << [PROTOCOL, protocol]
177
+ end
178
+
179
+ if length = response.body&.length
180
+ protocol_headers << [CONTENT_LENGTH, length]
181
+ end
182
+
183
+ headers = ::Protocol::HTTP::Headers::Merged.new(protocol_headers, response.headers)
184
+
185
+ if body = response.body and !self.head?
187
186
  @stream.send_headers(nil, headers)
188
- @stream.send_body(response.body)
187
+ @stream.send_body(body)
189
188
  else
190
- headers = ::Protocol::HTTP::Headers::Merged.new([
191
- [STATUS, response.status],
192
- ], response.headers)
189
+ # Ensure the response body is closed if we are ending the stream:
190
+ response.close
193
191
 
194
192
  @stream.send_headers(nil, headers, ::Protocol::HTTP2::END_STREAM)
195
-
196
- # If the response had a body but it was not sent, close it (e.g. HEAD request).
197
- response.body&.close
198
193
  end
199
194
  end
200
195
  end
@@ -75,13 +75,15 @@ module Async
75
75
 
76
76
  @response.headers = @headers
77
77
 
78
- unless @response.valid?
79
- send_reset_stream(::Protocol::HTTP2::Error::PROTOCOL_ERROR)
80
- else
81
- # We only construct the input/body if data is coming.
82
- unless end_stream
78
+ if @response.valid?
79
+ if !end_stream
80
+ # We only construct the input/body if data is coming.
83
81
  @response.body = prepare_input(@length)
82
+ elsif @response.head?
83
+ @response.body = ::Protocol::HTTP::Body::Head.new(@length)
84
84
  end
85
+ else
86
+ send_reset_stream(::Protocol::HTTP2::Error::PROTOCOL_ERROR)
85
87
  end
86
88
 
87
89
  self.notify!
@@ -140,6 +142,10 @@ module Async
140
142
  @stream.wait
141
143
  end
142
144
 
145
+ def head?
146
+ @request&.head?
147
+ end
148
+
143
149
  def valid?
144
150
  !!@status
145
151
  end
@@ -34,6 +34,7 @@ module Async
34
34
  super(length)
35
35
 
36
36
  @stream = stream
37
+ @remaining = length
37
38
  end
38
39
 
39
40
  def read
@@ -42,6 +43,17 @@ module Async
42
43
  @stream.request_window_update
43
44
  end
44
45
 
46
+ # We track the expected length and check we got what we were expecting.
47
+ if @remaining
48
+ if chunk
49
+ @remaining -= chunk.bytesize
50
+ elsif @remaining > 0
51
+ raise EOFError, "Expected #{self.length} bytes, #{@remaining} bytes short!"
52
+ elsif @remaining < 0
53
+ raise EOFError, "Expected #{self.length} bytes, #{@remaining} bytes over!"
54
+ end
55
+ end
56
+
45
57
  return chunk
46
58
  end
47
59
  end
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Async
24
24
  module HTTP
25
- VERSION = "0.50.6"
25
+ VERSION = "0.50.7"
26
26
  end
27
27
  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.50.6
4
+ version: 0.50.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-19 00:00:00.000000000 Z
11
+ date: 2020-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.14.1
61
+ version: 0.15.1
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.14.1
68
+ version: 0.15.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: protocol-http1
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -221,7 +221,9 @@ files:
221
221
  - README.md
222
222
  - Rakefile
223
223
  - async-http.gemspec
224
+ - bake.rb
224
225
  - bake/async/http.rb
226
+ - bake/async/http/h2spec.rb
225
227
  - examples/compare/Gemfile
226
228
  - examples/compare/benchmark.rb
227
229
  - examples/fetch/Gemfile
@@ -274,8 +276,6 @@ files:
274
276
  - lib/async/http/server.rb
275
277
  - lib/async/http/statistics.rb
276
278
  - lib/async/http/version.rb
277
- - tasks/h2spec.rake
278
- - tasks/server.rake
279
279
  homepage: https://github.com/socketry/async-http
280
280
  licenses:
281
281
  - MIT
@@ -1,45 +0,0 @@
1
-
2
- namespace :h2spec do
3
- task :build do
4
- # Fetch the code:
5
- sh "go get github.com/spf13/cobra"
6
- sh "go get github.com/summerwind/h2spec"
7
-
8
- # This builds `h2spec` into the current directory
9
- sh "go build ~/go/src/github.com/summerwind/h2spec/cmd/h2spec/h2spec.go"
10
- end
11
-
12
- task :server do
13
- require 'async/reactor'
14
- require 'async/container'
15
- require 'async/http/server'
16
- require 'async/io/host_endpoint'
17
-
18
- endpoint = Async::IO::Endpoint.tcp('127.0.0.1', 7272)
19
-
20
- server = Async::HTTP::Server.for(endpoint, Async::HTTP::Protocol::HTTP2, "https") do |request|
21
- Protocol::HTTP::Response[200, {'content-type' => 'text/plain'}, ["Hello World"]]
22
- end
23
-
24
- @container = Async::Container.new
25
-
26
- Async.logger.info(self){"Starting server..."}
27
- @container.run(count: 1) do
28
- server.run
29
- end
30
- end
31
-
32
- task :test => :server do
33
- begin
34
- if test = ENV['TEST']
35
- sh("./h2spec", test, "-p", "7272")
36
- else
37
- sh("./h2spec", "-p", "7272")
38
- end
39
- ensure
40
- @container.stop(false)
41
- end
42
- end
43
-
44
- task :all => [:build, :test]
45
- end
@@ -1,104 +0,0 @@
1
-
2
- task :http1 do
3
- require 'async/http/protocol'
4
- require 'async/http/endpoint'
5
- require 'async/io/host_endpoint'
6
-
7
- @protocol = Async::HTTP::Protocol::HTTP1
8
- end
9
-
10
- task :debug do
11
- require 'async/logger'
12
-
13
- Async.logger.level = Logger::DEBUG
14
- end
15
-
16
- task :google do
17
- require 'async'
18
- require 'pry'
19
-
20
- Async do
21
- endpoint = Async::HTTP::Endpoint.parse("https://www.google.com")
22
- peer = endpoint.connect
23
- stream = Async::IO::Stream.new(peer)
24
-
25
- framer = ::Protocol::HTTP2::Framer.new(stream)
26
- client = ::Protocol::HTTP2::Client.new(framer)
27
-
28
- client.send_connection_preface
29
-
30
- stream = ::Protocol::HTTP2::Stream.new(client)
31
-
32
- client.read_frame
33
- client.read_frame
34
-
35
- stream.send_headers(nil, [[':method', 'GET'], [':authority', 'www.google.com'], [':path', '/']], ::Protocol::HTTP2::END_STREAM)
36
-
37
- binding.pry
38
- end
39
- end
40
-
41
- task :server do
42
- require 'async/reactor'
43
- require 'async/container/forked'
44
- require 'async/http/server'
45
-
46
- server = Async::HTTP::Server.for(Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true), @protocol) do |request|
47
- return Protocol::HTTP::Response[200, {'content-type' => 'text/plain'}, ["Hello World"]]
48
- end
49
-
50
- container = Async::Container.new
51
-
52
- container.run(count: 1) do
53
- #GC.disable
54
-
55
- server.run
56
- end
57
-
58
- container.wait
59
- end
60
-
61
- task :benchmark do
62
- sh 'wrk -t 8 -c 8 -d 2 http://127.0.0.1:9294'
63
- end
64
-
65
- task :client do
66
- require 'async/reactor'
67
- require 'async/http/client'
68
-
69
- client = Async::HTTP::Client.new(Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true), @protocol)
70
-
71
- Async::Reactor.run do
72
- response = client.get("/")
73
-
74
- puts response.inspect
75
-
76
- client.close
77
- end
78
- end
79
-
80
- task :wrk do
81
- require 'async/reactor'
82
- require 'async/http/server'
83
- require 'async/container/forked'
84
-
85
- server = Async::HTTP::Server.for(Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true), @protocol) do |request|
86
- return Protocol::HTTP::Response[200, {'content-type' => 'text/plain'}, ["Hello World"]]
87
- end
88
-
89
- concurrency = 1
90
-
91
- container = Async::Container.new
92
-
93
- container.run(count: concurrency) do
94
- server.run
95
- end
96
-
97
- url = "http://127.0.0.1:9294/"
98
-
99
- 5.times do
100
- system("wrk", "-c", concurrency.to_s, "-d", "10", "-t", concurrency.to_s, url)
101
- end
102
-
103
- container.stop(false)
104
- end