async-http 0.33.2 → 0.34.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: 2018a5f45e997512850826ead70a696aa7a8cecfff16d4008776f4f11b0d3219
4
- data.tar.gz: 9850ab072b612c65c47769eec40ffe12b733b114542fb7be7a7582f0177f9932
3
+ metadata.gz: 5db5986fab5adcee4d194355593dc340928348d58d47e3fa7bc871808a1df9f4
4
+ data.tar.gz: f598d3fc50073ca60ff4f2a322317abc11ec54b08c71b1938448c7a661bdf787
5
5
  SHA512:
6
- metadata.gz: 5a4b16f09fdf6b9f985cf7bb9bdebce44dd521ff36af1836c756a5a12bcc7ea0240f42432fc4e26da65ce4f5008842c264827bee60ed6ac678f692a306cefd5b
7
- data.tar.gz: d4779932899b863951518920756008bb64a16d18536e3db62103c7beb3486e7379ac0d5252fbb579893058a430355151f086635e0e08dd8e59b43a9e4286b824
6
+ metadata.gz: '09bae9124371c5122da9410f95007d8acb1fa078cd829c31672bebb9eb1b81ee19238182d26a8b35b7e86e84335172ae85a444a7289c6361ad008a33fd906d43'
7
+ data.tar.gz: ea2afa56fc284d1e6b591818837ed3a35fd7379fa975dfd83194e5f77503f55dbf5f73aa4695b77b9b15c082cdc2963827167474dda8539c09dac48a210c8d0d
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
4
- $LOAD_PATH.unshift(File.expand_path("../../http-protocol/lib", __dir__))
2
+ #
3
+ # $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
4
+ # $LOAD_PATH.unshift(File.expand_path("../../http-protocol/lib", __dir__))
5
5
 
6
6
  require 'async'
7
7
  require 'async/logger'
@@ -54,6 +54,15 @@ module Async
54
54
  end
55
55
  end
56
56
 
57
+ # Write the body of the response to the given file path.
58
+ def save(path, mode = ::File::WRONLY, *args)
59
+ ::File.open(path, mode, *args) do |file|
60
+ self.each do |chunk|
61
+ file.write(chunk)
62
+ end
63
+ end
64
+ end
65
+
57
66
  # Close the connection as quickly as possible. Discards body. May close the underlying connection if necessary to terminate the stream.
58
67
  def close(error = nil)
59
68
  if @body
@@ -0,0 +1,55 @@
1
+ # Copyright, 2018, 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 'url_endpoint'
22
+ require_relative 'middleware'
23
+
24
+ module Async
25
+ module HTTP
26
+ class Internet
27
+ def initialize
28
+ @clients = {}
29
+ end
30
+
31
+ def call(method, url, headers = [], body = nil)
32
+ endpoint = URLEndpoint.parse(url)
33
+
34
+ client = @clients.fetch(endpoint) do
35
+ @clients[endpoint] = Client.new(endpoint)
36
+ end
37
+
38
+ request = Request.new(endpoint.authority, method, endpoint.path, nil, headers, body)
39
+
40
+ return client.call(request)
41
+ end
42
+
43
+ def close
44
+ @clients.each_value(&:close)
45
+ @clients.clear
46
+ end
47
+
48
+ VERBS.each do |verb|
49
+ define_method(verb.downcase) do |url, headers = [], body = nil|
50
+ self.call(verb, url.to_str, headers, body)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -32,7 +32,7 @@ module Async
32
32
 
33
33
  module Methods
34
34
  VERBS.each do |verb|
35
- define_method(verb.downcase) do |location, headers = {}, body = []|
35
+ define_method(verb.downcase) do |location, headers = [], body = []|
36
36
  self.call(Request[verb, location.to_str, headers, body])
37
37
  end
38
38
  end
@@ -72,7 +72,7 @@ module Async
72
72
  status == 500
73
73
  end
74
74
 
75
- def self.[](status, headers = {}, body = [])
75
+ def self.[](status, headers = [], body = nil)
76
76
  body = Body::Buffered.wrap(body)
77
77
 
78
78
  self.new(nil, status, nil, headers, body)
@@ -70,6 +70,10 @@ module Async
70
70
  secure? ? 443 : 80
71
71
  end
72
72
 
73
+ def default_port?
74
+ port == default_port
75
+ end
76
+
73
77
  def port
74
78
  @options[:port] || @url.port || default_port
75
79
  end
@@ -78,6 +82,18 @@ module Async
78
82
  @options[:hostname] || @url.hostname
79
83
  end
80
84
 
85
+ def authority
86
+ if default_port?
87
+ hostname
88
+ else
89
+ "#{hostname}:#{port}"
90
+ end
91
+ end
92
+
93
+ def path
94
+ @url.request_uri
95
+ end
96
+
81
97
  DEFAULT_ALPN_PROTOCOLS = ['h2', 'http/1.1'].freeze
82
98
 
83
99
  def alpn_protocols
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module HTTP
23
- VERSION = "0.33.2"
23
+ VERSION = "0.34.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.33.2
4
+ version: 0.34.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-10-14 00:00:00.000000000 Z
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -161,6 +161,7 @@ files:
161
161
  - lib/async/http/client.rb
162
162
  - lib/async/http/content_encoding.rb
163
163
  - lib/async/http/headers.rb
164
+ - lib/async/http/internet.rb
164
165
  - lib/async/http/middleware.rb
165
166
  - lib/async/http/middleware/builder.rb
166
167
  - lib/async/http/pool.rb