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 +4 -4
- data/.travis.yml +4 -0
- data/README.md +61 -0
- data/async-http.gemspec +4 -4
- data/lib/async/http/protocol/http1/connection.rb +1 -5
- data/lib/async/http/protocol/http1/server.rb +9 -3
- data/lib/async/http/url_endpoint.rb +6 -2
- data/lib/async/http/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d5710ca0e5393d6c5d440bc2bb6e075ca62cce760abe95d02e3b01ec2d79b58
|
4
|
+
data.tar.gz: 652291cc7346026cd4a314f064399abcddd27a8bb8c7cc61d6f541eb7a38972c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99039c2bb14d47197a5e827a73e80cce66c30b6366bcc67d2914685a6f4571c7467727c6e7d04ade97200c57eaf9a177066fe54344c469cf09fb2d38bbf804bd
|
7
|
+
data.tar.gz: 003b897a551cd4626c26668b12e41e89242dfddf0b68c3a76612574feb34f4ce3366802a15b18f54a4f00a756d2bf4c897c2f32224cdf0a68af951c745524229
|
data/.travis.yml
CHANGED
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
|
-
|
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.
|
20
|
-
spec.add_dependency("async-io", "~> 1.
|
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"
|
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
|
-
|
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
|
-
{
|
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
|
|
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.37.
|
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:
|
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.
|
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.
|
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.
|
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.
|
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: '
|
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: '
|
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.
|
219
|
+
rubygems_version: 3.0.1
|
220
220
|
signing_key:
|
221
221
|
specification_version: 4
|
222
222
|
summary: A HTTP client and server library.
|