async-http 0.16.0 → 0.17.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: '092da1fc3f7bb2f725d8e93dc47462ca276ea6d5ff613e2b93fb93ab85ebb9aa'
4
- data.tar.gz: ea9d3fb54fdd14a7150e764397ae94c81973e7fb3bf6b28ea4462f8b6c9d53c7
3
+ metadata.gz: 5e36c2e4c547a2fab5f4080479acd7fd4964194ded2bf10b0e1f596f0cedcbe0
4
+ data.tar.gz: 0eb2ced279e0fa57db73b4bdc4fb8a450cc1440b95dd96a0c694d804bb11a45c
5
5
  SHA512:
6
- metadata.gz: 3f44d4558088cecd292fcb276ea035118c587a0a0c9c25c3c5cf69b43d3924abc7f6b0abcecf5a9cf23aa04b9f530816d1f8e7dc6833c215e443f893bd0a6c6f
7
- data.tar.gz: 2c5bb797ba153a6bb224457e4b3304b08b0af39b21816e1a43fc2e01aa41970cc94e21fca4ee0914a61bab672d41ba862249776222051d564e59a2314c52001f
6
+ metadata.gz: 5f703f9ca20ef9a7c9675251f65575b0004de8e9757f2542167aaf330b6796522d5dcee0b219ffb528e388aee6970ae34aad18985d31f2e14821160d699245fc
7
+ data.tar.gz: ccf65ec4786912ec2636ad8c5ad13cac4e09c1b439c51c8b4efa342a11f03d4a7a78d807402fe608ad67a42d625b19a27a9d941e3f9c079c5d1c9a839c080783
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Async::HTTP
2
2
 
3
- A multi-process, multi-fiber HTTP client/server built on top of [async] and [async-io]. Each request is run within a light weight fiber and can block on up-stream requests without stalling the entire server process.
4
-
5
- *This code is a proof-of-concept and not intended (yet) for production use.* The entire stack requires more scrutiny both in terms of performance and security.
3
+ An asynchronous client and server implementation of HTTP/1.0, HTTP/1.1 and HTTP/2.0 including TLS. Support for streaming requests and responses. Built on top of [async] and [async-io]. [falcon] provides a rack-compatible server.
6
4
 
7
5
  [![Build Status](https://secure.travis-ci.org/socketry/async-http.svg)](http://travis-ci.org/socketry/async-http)
8
6
  [![Code Climate](https://codeclimate.com/github/socketry/async-http.svg)](https://codeclimate.com/github/socketry/async-http)
@@ -10,6 +8,7 @@ A multi-process, multi-fiber HTTP client/server built on top of [async] and [asy
10
8
 
11
9
  [async]: https://github.com/socketry/async
12
10
  [async-io]: https://github.com/socketry/async-io
11
+ [falcon]: https://github.com/socketry/falcon
13
12
 
14
13
  ## Installation
15
14
 
data/async-http.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.authors = ["Samuel Williams"]
8
8
  spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
9
 
10
- spec.summary = ""
10
+ spec.summary = "A HTTP client and server library."
11
11
  spec.homepage = "https://github.com/socketry/async-http"
12
12
 
13
13
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency("async", "~> 1.5")
20
- spec.add_dependency("async-io", "~> 1.6")
20
+ spec.add_dependency("async-io", "~> 1.7")
21
21
 
22
22
  spec.add_dependency("http-2", "~> 0.8")
23
23
  # spec.add_dependency("openssl")
@@ -22,11 +22,12 @@ require 'async/queue'
22
22
 
23
23
  module Async
24
24
  module HTTP
25
- class Body < Async::Queue
25
+ class Body
26
26
  def initialize
27
- super
27
+ @queue = Async::Queue.new
28
28
 
29
29
  @finished = false
30
+ @stopped = false
30
31
  end
31
32
 
32
33
  def finished?
@@ -34,19 +35,26 @@ module Async
34
35
  end
35
36
 
36
37
  def each
38
+ return to_enum unless block_given?
39
+
37
40
  return if @finished
38
41
 
39
- while chunk = self.dequeue
42
+ while chunk = @queue.dequeue
40
43
  yield chunk
41
44
  end
45
+ rescue
46
+ # Stop the stream because the remote end is no longer reading from it. Any attempt to write to the stream will fail.
47
+ @stopped = $!
42
48
 
49
+ raise
50
+ ensure
43
51
  @finished = true
44
52
  end
45
53
 
46
54
  def read
47
55
  return if @finished
48
56
 
49
- unless chunk = self.dequeue
57
+ unless chunk = @queue.dequeue
50
58
  @finished = true
51
59
  end
52
60
 
@@ -63,14 +71,18 @@ module Async
63
71
  return buffer
64
72
  end
65
73
 
66
- alias join read
67
-
68
74
  def write(chunk)
69
- self.enqueue(chunk)
75
+ if @stopped
76
+ raise @stopped
77
+ end
78
+
79
+ # TODO should this yield if the queue is full?
80
+
81
+ @queue.enqueue(chunk)
70
82
  end
71
83
 
72
84
  def finish
73
- self.enqueue(nil)
85
+ @queue.enqueue(nil)
74
86
  end
75
87
  end
76
88
 
@@ -217,8 +229,6 @@ module Async
217
229
  return buffer
218
230
  end
219
231
 
220
- alias join read
221
-
222
232
  def finish
223
233
  read
224
234
  end
@@ -86,6 +86,8 @@ module Async
86
86
  @endpoint.each do |endpoint|
87
87
  peer = endpoint.connect
88
88
 
89
+ peer.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
90
+
89
91
  stream = IO::Stream.new(peer)
90
92
 
91
93
  break @protocol.client(stream)
@@ -39,6 +39,8 @@ module Async
39
39
  end
40
40
 
41
41
  def accept(peer, address, task: Task.current)
42
+ peer.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
43
+
42
44
  stream = Async::IO::Stream.new(peer)
43
45
  protocol = @protocol_class.server(stream)
44
46
 
@@ -56,7 +58,6 @@ module Async
56
58
  end
57
59
  rescue EOFError, Errno::ECONNRESET, Errno::EPIPE
58
60
  # Sometimes client will disconnect without completing a result or reading the entire buffer.
59
- return nil
60
61
  ensure
61
62
  peer.close
62
63
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module HTTP
23
- VERSION = "0.16.0"
23
+ VERSION = "0.17.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.16.0
4
+ version: 0.17.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-10 00:00:00.000000000 Z
11
+ date: 2018-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '1.7'
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.6'
40
+ version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: http-2
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -160,5 +160,5 @@ rubyforge_project:
160
160
  rubygems_version: 2.7.6
161
161
  signing_key:
162
162
  specification_version: 4
163
- summary: ''
163
+ summary: A HTTP client and server library.
164
164
  test_files: []