async-http 0.37.7 → 0.37.9

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: 574519636dc41abd3e1da545016ea0fce7094f22af9a8071cbd47bf182e1a39a
4
- data.tar.gz: f5acbdcfca9bef6d779f2c1b20d38dd0ebb3a17beb29090faef7ca4388c13d5b
3
+ metadata.gz: 7d5710ca0e5393d6c5d440bc2bb6e075ca62cce760abe95d02e3b01ec2d79b58
4
+ data.tar.gz: 652291cc7346026cd4a314f064399abcddd27a8bb8c7cc61d6f541eb7a38972c
5
5
  SHA512:
6
- metadata.gz: a202779e32f46dd24eaf23f791f003118f728c9846f4608778c7111aaebad02bfe39a5346363b7f3d3631f01ca6b5deafe626bb87a5744dd7ea03f06429b5ac3
7
- data.tar.gz: 7fa9b73b247ed2c7abd2b812aa6621d35dfc5a4461f2e7cb6c3aa1457fdf797a365f97c9f5bbe90c3addd195fe2b3207c23a2cabee61532c76336e7287fafdcf
6
+ metadata.gz: 99039c2bb14d47197a5e827a73e80cce66c30b6366bcc67d2914685a6f4571c7467727c6e7d04ade97200c57eaf9a177066fe54344c469cf09fb2d38bbf804bd
7
+ data.tar.gz: 003b897a551cd4626c26668b12e41e89242dfddf0b68c3a76612574feb34f4ce3366802a15b18f54a4f00a756d2bf4c897c2f32224cdf0a68af951c745524229
data/.travis.yml CHANGED
@@ -2,6 +2,10 @@ language: ruby
2
2
  dist: xenial
3
3
  cache: bundler
4
4
 
5
+ before_install:
6
+ - gem update --system
7
+ - gem install bundler
8
+
5
9
  addons:
6
10
  apt:
7
11
  packages:
data/README.md CHANGED
@@ -28,6 +28,67 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage
30
30
 
31
+ ### Post JSON data
32
+
33
+ Here is an example showing how to post a data structure as JSON to a remote resource:
34
+
35
+ ```ruby
36
+ #!/usr/bin/env ruby
37
+
38
+ require 'json'
39
+ require 'async'
40
+ require 'async/http/internet'
41
+
42
+ data = {'life' => 42}
43
+
44
+ Async.run do
45
+ # Make a new internet:
46
+ internet = Async::HTTP::Internet.new
47
+
48
+ # Prepare the request:
49
+ headers = [['accept', 'application/json']]
50
+ body = [JSON.dump(data)]
51
+
52
+ # Issues a POST request:
53
+ response = internet.post("https://httpbin.org/anything", headers, body)
54
+
55
+ # Save the response body to a local file:
56
+ pp JSON.parse(response.read)
57
+ ensure
58
+ # The internet is closed for business:
59
+ internet.close
60
+ end
61
+ ```
62
+
63
+ Consider using [async-rest](https://github.com/socketry/async-rest) instead.
64
+
65
+ ### Downloading a File
66
+
67
+ Here is an example showing how to download a file and save it to a local path:
68
+
69
+ ```ruby
70
+ #!/usr/bin/env ruby
71
+
72
+ require 'async'
73
+ require 'async/http/internet'
74
+
75
+ Async.run do
76
+ # Make a new internet:
77
+ internet = Async::HTTP::Internet.new
78
+
79
+ # Issues a GET request to Google:
80
+ response = internet.get("https://www.google.com/search?q=kittens")
81
+
82
+ # Save the response body to a local file:
83
+ response.save("/tmp/search.html")
84
+ ensure
85
+ # The internet is closed for business:
86
+ internet.close
87
+ end
88
+ ```
89
+
90
+ ### Basic Client/Server
91
+
31
92
  Here is a basic example of a client/server running in the same reactor:
32
93
 
33
94
  ```ruby
data/async-http.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+
2
2
  require_relative 'lib/async/http/version'
3
3
 
4
4
  Gem::Specification.new do |spec|
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f)}
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency("async", "~> 1.6")
20
- spec.add_dependency("async-io", "~> 1.16")
19
+ spec.add_dependency("async", "~> 1.14")
20
+ spec.add_dependency("async-io", "~> 1.18")
21
21
 
22
22
  spec.add_dependency("http-protocol", "~> 0.10")
23
23
 
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "async-rspec", "~> 1.10"
27
27
  spec.add_development_dependency "async-container", "~> 0.5.0"
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.3"
29
+ spec.add_development_dependency "bundler"
30
30
  spec.add_development_dependency "rspec", "~> 3.6"
31
31
  spec.add_development_dependency "rake"
32
32
  end
@@ -39,12 +39,8 @@ module Async
39
39
 
40
40
  attr :version
41
41
 
42
- CRLF = "\r\n"
43
-
44
- attr :stream
45
-
46
42
  def read_line
47
- @stream.read_until(CRLF) or raise EOFError
43
+ @stream.read_until(CRLF) or raise EOFError, "Could not read line"
48
44
  end
49
45
 
50
46
  # @return [Async::Wrapper] the underlying non-blocking IO.
@@ -25,6 +25,11 @@ module Async
25
25
  module Protocol
26
26
  module HTTP1
27
27
  class Server < Connection
28
+ def fail_request(status)
29
+ @persistent = false
30
+ write_response(@version, status, {}, nil)
31
+ end
32
+
28
33
  def next_request
29
34
  # The default is true.
30
35
  return nil unless @persistent
@@ -36,10 +41,11 @@ module Async
36
41
  end
37
42
 
38
43
  return request
44
+ rescue Async::TimeoutError
45
+ fail_request(408)
46
+ raise
39
47
  rescue
40
- # Bad Request
41
- write_response(@version, 400, {}, nil)
42
-
48
+ fail_request(400)
43
49
  raise
44
50
  end
45
51
 
@@ -143,7 +143,10 @@ module Async
143
143
  end
144
144
 
145
145
  def tcp_options
146
- {reuse_port: @options[:reuse_port] ? true : false}
146
+ {
147
+ reuse_port: self.reuse_port,
148
+ timeout: self.timeout,
149
+ }
147
150
  end
148
151
 
149
152
  def build_endpoint(endpoint = nil)
@@ -153,7 +156,8 @@ module Async
153
156
  # Wrap it in SSL:
154
157
  return Async::IO::SSLEndpoint.new(endpoint,
155
158
  ssl_context: self.ssl_context,
156
- hostname: self.hostname
159
+ hostname: self.hostname,
160
+ timeout: self.timeout,
157
161
  )
158
162
  end
159
163
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module HTTP
23
- VERSION = "0.37.7"
23
+ VERSION = "0.37.9"
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.7
4
+ version: 0.37.9
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-12-20 00:00:00.000000000 Z
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.14'
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.6'
26
+ version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: async-io
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.16'
33
+ version: '1.18'
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.16'
40
+ version: '1.18'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: http-protocol
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '1.3'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '1.3'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -216,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  requirements: []
219
- rubygems_version: 3.0.0.beta3
219
+ rubygems_version: 3.0.1
220
220
  signing_key:
221
221
  specification_version: 4
222
222
  summary: A HTTP client and server library.