httpx 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06cc2e51d9b985b5df5b830bcfcdbcde9170253cc90b914dbb54c903106e8627
4
- data.tar.gz: c1cd4de4e8ef8b1792b4b9e2ef12ff4abda3e101a82add4aeb580953ea641460
3
+ metadata.gz: b31d47dee309cce01caf25b3bc2f9fe51f602e9e2b07318c0903dee4b6d5b0c2
4
+ data.tar.gz: 18d8eb569ef7b5cf989ee61a85ed747cf9ceb1098d37e102fe7a721ae00675d8
5
5
  SHA512:
6
- metadata.gz: da578cf07f612ab7af2f499aad38aa71e8b8cb447da80f2c0274e75e2364599e1bcccde9cd5ef82ca14078d3a3a7bce9ee533f3ad11f35efba448761b492a496
7
- data.tar.gz: 1c339abaf5e9f56641546b814c0b073867db4d0aa2c7b44dc5bc7049552b8a8c11dd0743b66f21a8d99bf7bab855b98768c1eb292c3e89400863a9abe1a8f53f
6
+ metadata.gz: c2fd3831074357bc36389c299f257f1b14cd70f94d3491125bc54ef67e485dac66f9f2457b013a25c7b298a6926cb0bb92436cf07f3e9bd1d9f5e850f63fa443
7
+ data.tar.gz: 498440a319ff97e08236dde05cd6413723e17f6be9b4d4ce110b59fe88e4da0a9254cbd639adc28a6c81a6183eb70fbd7dd38719716c480d00addfed409ca446
@@ -80,7 +80,16 @@ module HTTPX
80
80
  def match?(uri, options)
81
81
  return false if @state == :closing || @state == :closed
82
82
 
83
- (@origins.include?(uri.origin) || match_altsvcs?(uri)) && @options == options
83
+ (
84
+ (
85
+ @origins.include?(uri.origin) &&
86
+ # if there is more than one origin to match, it means that this connection
87
+ # was the result of coalescing. To prevent blind trust in the case where the
88
+ # origin came from an ORIGIN frame, we're going to verify the hostname with the
89
+ # SSL certificate
90
+ (@origins.size == 1 || @origin == uri.origin || (@io && @io.verify_hostname(uri.host)))
91
+ ) || match_altsvcs?(uri)
92
+ ) && @options == options
84
93
  end
85
94
 
86
95
  def mergeable?(connection)
@@ -102,8 +111,8 @@ module HTTPX
102
111
  def merge(connection)
103
112
  @origins += connection.instance_variable_get(:@origins)
104
113
  pending = connection.instance_variable_get(:@pending)
105
- pending.each do |req, args|
106
- send(req, args)
114
+ pending.each do |req|
115
+ send(req)
107
116
  end
108
117
  end
109
118
 
@@ -121,7 +130,7 @@ module HTTPX
121
130
  def purge_pending
122
131
  [@parser.pending, @pending].each do |pending|
123
132
  pending.reject! do |request, *args|
124
- yield(request, args)
133
+ yield(request, args) if block_given?
125
134
  end
126
135
  end
127
136
  end
@@ -129,10 +138,11 @@ module HTTPX
129
138
  # checks if this is connection is an alternative service of
130
139
  # +uri+
131
140
  def match_altsvcs?(uri)
132
- AltSvc.cached_altsvc(@origin).any? do |altsvc|
133
- origin = altsvc["origin"]
134
- origin.altsvc_match?(uri.origin)
135
- end
141
+ @origins.any? { |origin| uri.altsvc_match?(origin) } ||
142
+ AltSvc.cached_altsvc(@origin).any? do |altsvc|
143
+ origin = altsvc["origin"]
144
+ origin.altsvc_match?(uri.origin)
145
+ end
136
146
  end
137
147
 
138
148
  def connecting?
@@ -274,6 +284,9 @@ module HTTPX
274
284
  parser.on(:promise) do |request, stream|
275
285
  request.emit(:promise, parser, stream)
276
286
  end
287
+ parser.on(:origin) do |origin|
288
+ @origins << origin
289
+ end
277
290
  parser.on(:close) do
278
291
  transition(:closing)
279
292
  end
@@ -9,6 +9,8 @@ module HTTPX
9
9
 
10
10
  CRLF = "\r\n"
11
11
 
12
+ attr_reader :pending
13
+
12
14
  def initialize(buffer, options)
13
15
  @options = Options.new(options)
14
16
  @max_concurrent_requests = @options.max_concurrent_requests
@@ -41,7 +41,7 @@ module HTTPX
41
41
 
42
42
  def send(request, **)
43
43
  if !@handshake_completed ||
44
- @connection.active_stream_count >= @max_concurrent_requests
44
+ @streams.size >= @max_concurrent_requests
45
45
  @pending << request
46
46
  return
47
47
  end
@@ -107,6 +107,7 @@ module HTTPX
107
107
  @connection.on(:frame, &method(:on_frame))
108
108
  @connection.on(:frame_sent, &method(:on_frame_sent))
109
109
  @connection.on(:frame_received, &method(:on_frame_received))
110
+ @connection.on(:origin, &method(:on_origin))
110
111
  @connection.on(:promise, &method(:on_promise))
111
112
  @connection.on(:altsvc) { |frame| on_altsvc(frame[:origin], frame) }
112
113
  @connection.on(:settings_ack, &method(:on_settings))
@@ -224,7 +225,7 @@ module HTTPX
224
225
  emit(:error, request, ex)
225
226
  end
226
227
  end
227
- return unless @connection.state == :closed && @connection.active_stream_count.zero?
228
+ return unless @connection.state == :closed && @streams.size.zero?
228
229
 
229
230
  emit(:close)
230
231
  end
@@ -265,6 +266,10 @@ module HTTPX
265
266
  emit(:promise, @streams.key(stream.parent), stream)
266
267
  end
267
268
 
269
+ def on_origin(origin)
270
+ emit(:origin, origin)
271
+ end
272
+
268
273
  def respond_to_missing?(meth, *args)
269
274
  @connection.respond_to?(meth, *args) || super
270
275
  end
@@ -67,10 +67,11 @@ module HTTPX
67
67
 
68
68
  def altsvc_match?(uri)
69
69
  uri = URI.parse(uri)
70
- self == uri || begin
70
+
71
+ origin == uri.origin || begin
71
72
  case scheme
72
- when 'h2'
73
- uri.scheme == "https" &&
73
+ when "h2"
74
+ (uri.scheme == "https" || uri.scheme == "h2") &&
74
75
  host == uri.host &&
75
76
  (port || default_port) == (uri.port || uri.default_port)
76
77
  else
@@ -30,7 +30,7 @@ module HTTPX
30
30
 
31
31
  def verify_hostname(host)
32
32
  return false if @ctx.verify_mode == OpenSSL::SSL::VERIFY_NONE
33
- return false if @io.peer_cert.nil?
33
+ return false if !@io.respond_to?(:peer_cert) || @io.peer_cert.nil?
34
34
 
35
35
  OpenSSL::SSL.verify_certificate_identity(@io.peer_cert, host)
36
36
  end
@@ -90,6 +90,7 @@ module HTTPX
90
90
 
91
91
  if found_connection.state == :open
92
92
  coalesce_connections(found_connection, connection)
93
+ throw(:coalesced, found_connection)
93
94
  else
94
95
  found_connection.once(:open) do
95
96
  coalesce_connections(found_connection, connection)
@@ -32,7 +32,7 @@ module HTTPX
32
32
  end
33
33
  log(label: "resolver: ") { "answer #{connection.origin.host}: #{addresses.inspect}" }
34
34
  connection.addresses = addresses
35
- emit(:resolve, connection)
35
+ catch(:coalesced) { emit(:resolve, connection) }
36
36
  end
37
37
 
38
38
  def early_resolve(connection, hostname: connection.origin.host)
@@ -93,15 +93,12 @@ module HTTPX
93
93
  # incidentally, all requests will be re-routed to the first
94
94
  # advertised alt-svc, which incidentally follows the spec.
95
95
  existing_connection.purge_pending do |request|
96
- is_idle = request.origin == origin &&
97
- request.state == :idle &&
98
- !request.headers.key?("alt-used")
99
- if is_idle
100
- log(level: 1) { "#{origin} alt-svc: sending #{request.uri} to #{alt_origin}" }
101
- connection.send(request)
102
- end
103
- is_idle
96
+ request.origin == origin &&
97
+ request.state == :idle &&
98
+ !request.headers.key?("alt-used")
104
99
  end
100
+
101
+ connection.merge(existing_connection)
105
102
  rescue UnsupportedSchemeError
106
103
  altsvc["noop"] = true
107
104
  end
@@ -137,18 +134,17 @@ module HTTPX
137
134
  case uri.scheme
138
135
  when "http"
139
136
  "tcp"
140
- when "https"
141
- "ssl"
142
- when "h2"
143
- options = options.merge(ssl: { alpn_protocols: %w[h2] })
137
+ when "https", "h2"
144
138
  "ssl"
145
139
  else
146
140
  raise UnsupportedSchemeError, "#{uri}: #{uri.scheme}: unsupported URI scheme"
147
141
  end
148
142
  end
149
143
  connection = options.connection_class.new(type, uri, options)
150
- pool.init_connection(connection, options)
151
- connection
144
+ catch(:coalesced) do
145
+ pool.init_connection(connection, options)
146
+ connection
147
+ end
152
148
  end
153
149
 
154
150
  def send_requests(*requests, options)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "0.6.2"
4
+ VERSION = "0.6.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-30 00:00:00.000000000 Z
11
+ date: 2019-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next