async-http 0.37.14 → 0.38.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e41394903c83a4373a71c00c425e43de172f4200f4f333bb9495239e333ff10
4
- data.tar.gz: d5f4bd64ccdb86f5aa63645460da3dc0b28113da37bb07a80dfcea9066a5b00f
3
+ metadata.gz: 89e83fd398432897302be1ddbb07fad391a285216320e282e218c2faf07f4183
4
+ data.tar.gz: c9f37f4776390db5b0d050845397d7b530b145b6072f062b453957944683d7d6
5
5
  SHA512:
6
- metadata.gz: 91a24f4cd7fe39fd844e19b78052d5d813c1af5637da31f36e599e61316d7e120347e3ef18415ab243afe3667affa438671d1d3e43667ba2c8e0ad11233321b0
7
- data.tar.gz: 76162e9805315cc4bab01fed4ae9cc465b352134d052cffdbe037b69177cfa0fd20f4094f5d83952b6c7b41b65c8cf022e4c715404f6f96a7c02e03fb39153b1
6
+ metadata.gz: 53f726aec29bd9130015446d9e05b5b11be437c85978f9cb6d22647ebd17dd033182e647dda82c31bfb42e14cf01b9c1b8bae904e781370564f33df390470916
7
+ data.tar.gz: c698697b2d53e17a2321d430b01cd5746ef4eaf5623cb59b8a08200f86c4d3357037d85444c4141b23198bf4eba1aedd4915c8e79646717a761c02e8dd7d79b9
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency("async", "~> 1.14")
20
20
  spec.add_dependency("async-io", "~> 1.18")
21
21
 
22
- spec.add_dependency("http-protocol", "~> 0.12")
22
+ spec.add_dependency("http-protocol", "~> 0.15")
23
23
 
24
24
  # spec.add_dependency("openssl")
25
25
 
@@ -33,7 +33,7 @@ module Async
33
33
  }
34
34
 
35
35
  SERVER_SETTINGS = {
36
- ::HTTP::Protocol::HTTP2::Settings::ENABLE_PUSH => 0,
36
+ ::HTTP::Protocol::HTTP2::Settings::ENABLE_PUSH => 1,
37
37
  # We choose a lower maximum concurrent streams to avoid overloading a single connection/thread.
38
38
  ::HTTP::Protocol::HTTP2::Settings::MAXIMUM_CONCURRENT_STREAMS => 32,
39
39
  ::HTTP::Protocol::HTTP2::Settings::MAXIMUM_FRAME_SIZE => 0x100000,
@@ -57,6 +57,20 @@ module Async
57
57
 
58
58
  return server
59
59
  end
60
+
61
+ module WithPush
62
+ CLIENT_SETTINGS = HTTP2::CLIENT_SETTINGS.merge(
63
+ ::HTTP::Protocol::HTTP2::Settings::ENABLE_PUSH => 1,
64
+ )
65
+
66
+ def self.client(stream, settings = CLIENT_SETTINGS)
67
+ HTTP2.client(stream, settings)
68
+ end
69
+
70
+ def self.server(stream, settings = SERVER_SETTINGS)
71
+ HTTP2.server(stream, settings)
72
+ end
73
+ end
60
74
  end
61
75
  end
62
76
  end
@@ -68,6 +68,8 @@ module Async
68
68
  end
69
69
  end
70
70
 
71
+ attr :promises
72
+
71
73
  def peer
72
74
  @stream.io
73
75
  end
@@ -0,0 +1,71 @@
1
+ # Copyright, 2019, 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 '../response'
22
+
23
+ module Async
24
+ module HTTP
25
+ module Protocol
26
+ module HTTP2
27
+ class Promise < Response
28
+ def initialize(protocol, headers, stream_id)
29
+ super(protocol, stream_id)
30
+
31
+ @request = build_request(headers)
32
+ end
33
+
34
+ attr :stream
35
+ attr :request
36
+
37
+ private def build_request(headers)
38
+ request = HTTP::Request.new
39
+ request.headers = Headers.new
40
+
41
+ headers.each do |key, value|
42
+ if key == SCHEME
43
+ return @stream.send_failure(400, "Request scheme already specified") if request.scheme
44
+
45
+ request.scheme = value
46
+ elsif key == AUTHORITY
47
+ return @stream.send_failure(400, "Request authority already specified") if request.authority
48
+
49
+ request.authority = value
50
+ elsif key == METHOD
51
+ return @stream.send_failure(400, "Request method already specified") if request.method
52
+
53
+ request.method = value
54
+ elsif key == PATH
55
+ return @stream.send_failure(400, "Request path already specified") if request.path
56
+
57
+ request.path = value
58
+ else
59
+ request.headers[key] = value
60
+ end
61
+ end
62
+
63
+ return request
64
+ end
65
+
66
+ undef send_request
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -40,6 +40,36 @@ module Async
40
40
  false
41
41
  end
42
42
 
43
+ def push?
44
+ @protocol.enable_push?
45
+ end
46
+
47
+ def create_promise_stream(headers, stream_id)
48
+ request = self.class.new(@protocol, stream_id)
49
+ request.receive_headers(self, headers, false)
50
+
51
+ return request.stream
52
+ end
53
+
54
+ # @return [Stream] the promised stream, on which to send data.
55
+ def push(path, headers = nil)
56
+ push_headers = [
57
+ [SCHEME, @scheme],
58
+ [METHOD, GET],
59
+ [PATH, path],
60
+ [AUTHORITY, @authority]
61
+ ]
62
+
63
+ if headers
64
+ push_headers = Headers::Merged.new(
65
+ push_headers,
66
+ headers
67
+ )
68
+ end
69
+
70
+ @stream.send_push_promise(push_headers)
71
+ end
72
+
43
73
  def receive_headers(stream, headers, end_stream)
44
74
  headers.each do |key, value|
45
75
  if key == SCHEME
@@ -36,6 +36,20 @@ module Async
36
36
 
37
37
  @notification = Async::Notification.new
38
38
  @exception = nil
39
+
40
+ @promises = nil
41
+ end
42
+
43
+ def promises
44
+ @promises ||= Async::Queue.new
45
+ end
46
+
47
+ def create_promise_stream(headers, stream_id)
48
+ promise = Promise.new(@protocol, headers, stream_id)
49
+
50
+ self.promises.enqueue(promise)
51
+
52
+ return promise.stream
39
53
  end
40
54
 
41
55
  # Notify anyone waiting on the response headers to be received (or failure).
@@ -44,6 +58,10 @@ module Async
44
58
  @notification.signal
45
59
  @notification = nil
46
60
  end
61
+
62
+ # if @input
63
+ # @input.close(@exception)
64
+ # end
47
65
  end
48
66
 
49
67
  # Wait for the headers to be received or for stream reset.
@@ -20,6 +20,7 @@
20
20
 
21
21
  require_relative 'connection'
22
22
  require_relative 'request'
23
+ require_relative 'promise'
23
24
 
24
25
  require 'http/protocol/http2/server'
25
26
 
@@ -39,6 +39,10 @@ module Async
39
39
  attr_accessor :delegate
40
40
  attr :body
41
41
 
42
+ def create_promise_stream(headers, stream_id)
43
+ @delegate.create_promise_stream(headers, stream_id)
44
+ end
45
+
42
46
  def send_body(body, task: Async::Task.current)
43
47
  # TODO Might need to stop this task when body is cancelled.
44
48
  @task = task.async do |subtask|
@@ -100,7 +104,7 @@ module Async
100
104
  def receive_headers(frame)
101
105
  headers = super
102
106
 
103
- delegate.receive_headers(self, headers, frame.end_stream?)
107
+ @delegate.receive_headers(self, headers, frame.end_stream?)
104
108
 
105
109
  return headers
106
110
  end
@@ -109,7 +113,7 @@ module Async
109
113
  data = super
110
114
 
111
115
  if data
112
- delegate.receive_data(self, data, frame.end_stream?)
116
+ @delegate.receive_data(self, data, frame.end_stream?)
113
117
  end
114
118
 
115
119
  return data
@@ -123,7 +127,7 @@ module Async
123
127
  @body = nil
124
128
  end
125
129
 
126
- delegate.receive_reset_stream(self, error_code)
130
+ @delegate.receive_reset_stream(self, error_code)
127
131
 
128
132
  return error_code
129
133
  end
@@ -134,7 +138,7 @@ module Async
134
138
  @body = nil
135
139
  end
136
140
 
137
- delegate.stop_connection(error)
141
+ @delegate.stop_connection(error)
138
142
  end
139
143
  end
140
144
  end
@@ -38,6 +38,10 @@ module Async
38
38
  false
39
39
  end
40
40
 
41
+ def push?
42
+ false
43
+ end
44
+
41
45
  def peer
42
46
  if @protocol
43
47
  @protocol.peer
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module HTTP
23
- VERSION = "0.37.14"
23
+ VERSION = "0.38.0"
24
24
  end
25
25
  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.37.14
4
+ version: 0.38.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-02-08 00:00:00.000000000 Z
11
+ date: 2019-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.12'
47
+ version: '0.15'
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.12'
54
+ version: '0.15'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: async-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -183,6 +183,7 @@ files:
183
183
  - lib/async/http/protocol/http2.rb
184
184
  - lib/async/http/protocol/http2/client.rb
185
185
  - lib/async/http/protocol/http2/connection.rb
186
+ - lib/async/http/protocol/http2/promise.rb
186
187
  - lib/async/http/protocol/http2/request.rb
187
188
  - lib/async/http/protocol/http2/response.rb
188
189
  - lib/async/http/protocol/http2/server.rb