excon 0.80.1 → 0.81.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: b96db9f808328df275dda578ca7d075529a54ac44ca25f23fdc22442801e8afd
4
- data.tar.gz: ef6463db8fcd122b1cc926a4f7e3814e5b2f999d1a4b49a1ac64a7940359b980
3
+ metadata.gz: faa033f8191dff08e7476d47c1771112a841d7c4e762462afd069dedfdfc0a48
4
+ data.tar.gz: ade28a41a3ea482d33620df5902c17b6c8909d3e8348d60241e8e43925136015
5
5
  SHA512:
6
- metadata.gz: 8c5c00d0e25f9244ddc5b6a72ba43ec7384f31542aef90178340d36b7e720b43b9fc1af0a3a8dc4944e4eb43f2c6b8bd8df1933ed5822c4895a4fbe92666fb41
7
- data.tar.gz: dc901ce0e85af7d86ad4fb7066b5d2c3b5329e00d5a4b8c90b7103826372762583f9aa51f47d0c3c608f0e898d41c8308429fd3eddd4893d086c763ede44fa10
6
+ metadata.gz: 52ec74ebab2ab0057eaaa30255f73771088b70046df1478d0383f50e3067c73f5a3f33dbc9b6c8029df8f69d2e1104404bd032be113ca089b997ee5da63132fc
7
+ data.tar.gz: 9ec35940b326afae1467d00a29c17cc4ab003bc92701400251a44ec91f8961a1156152fab4219e5f1556eb3b5f06fc32613f5d553ceab04172f185c024f6dac3
@@ -115,7 +115,7 @@ module Excon
115
115
  # we already have data from a middleware, so bail
116
116
  return datum
117
117
  else
118
- socket.data = datum
118
+ socket(datum)
119
119
  # start with "METHOD /path"
120
120
  request = datum[:method].to_s.upcase + ' '
121
121
  if datum[:proxy] && datum[:scheme] != HTTPS
@@ -144,35 +144,25 @@ module Excon
144
144
  end
145
145
 
146
146
  # add headers to request
147
- datum[:headers].each do |key, values|
148
- if key.to_s.match(/[\r\n]/)
149
- raise Excon::Errors::InvalidHeaderKey.new(key.to_s.inspect + ' contains forbidden "\r" or "\n"')
150
- end
151
- [values].flatten.each do |value|
152
- if value.to_s.match(/[\r\n]/)
153
- raise Excon::Errors::InvalidHeaderValue.new(value.to_s.inspect + ' contains forbidden "\r" or "\n"')
154
- end
155
- request << key.to_s << ': ' << value.to_s << CR_NL
156
- end
157
- end
147
+ request << Utils.headers_hash_to_s(datum[:headers])
158
148
 
159
149
  # add additional "\r\n" to indicate end of headers
160
150
  request << CR_NL
161
151
 
162
152
  if datum.has_key?(:request_block)
163
- socket.write(request) # write out request + headers
153
+ socket(datum).write(request) # write out request + headers
164
154
  while true # write out body with chunked encoding
165
155
  chunk = datum[:request_block].call
166
156
  chunk = binary_encode(chunk)
167
157
  if chunk.length > 0
168
- socket.write(chunk.length.to_s(16) << CR_NL << chunk << CR_NL)
158
+ socket(datum).write(chunk.length.to_s(16) << CR_NL << chunk << CR_NL)
169
159
  else
170
- socket.write(String.new("0#{CR_NL}#{CR_NL}"))
160
+ socket(datum).write(String.new("0#{CR_NL}#{CR_NL}"))
171
161
  break
172
162
  end
173
163
  end
174
164
  elsif body.nil?
175
- socket.write(request) # write out request + headers
165
+ socket(datum).write(request) # write out request + headers
176
166
  else # write out body
177
167
  if body.respond_to?(:binmode) && !body.is_a?(StringIO)
178
168
  body.binmode
@@ -186,13 +176,13 @@ module Excon
186
176
  chunk = body.read([datum[:chunk_size] - request.length, 0].max)
187
177
  if chunk
188
178
  chunk = binary_encode(chunk)
189
- socket.write(request << chunk)
179
+ socket(datum).write(request << chunk)
190
180
  else
191
- socket.write(request) # write out request + headers
181
+ socket(datum).write(request) # write out request + headers
192
182
  end
193
183
 
194
184
  while (chunk = body.read(datum[:chunk_size]))
195
- socket.write(chunk)
185
+ socket(datum).write(chunk)
196
186
  end
197
187
  end
198
188
  end
@@ -463,14 +453,14 @@ module Excon
463
453
  end
464
454
  end
465
455
 
466
- def socket
467
- unix_proxy = @data[:proxy] ? @data[:proxy][:scheme] == UNIX : false
468
- sockets[@socket_key] ||= if @data[:scheme] == UNIX || unix_proxy
469
- Excon::UnixSocket.new(@data)
470
- elsif @data[:ssl_uri_schemes].include?(@data[:scheme])
471
- Excon::SSLSocket.new(@data)
456
+ def socket(datum = @data)
457
+ unix_proxy = datum[:proxy] ? datum[:proxy][:scheme] == UNIX : false
458
+ sockets[@socket_key] ||= if datum[:scheme] == UNIX || unix_proxy
459
+ Excon::UnixSocket.new(datum)
460
+ elsif datum[:ssl_uri_schemes].include?(datum[:scheme])
461
+ Excon::SSLSocket.new(datum)
472
462
  else
473
- Excon::Socket.new(@data)
463
+ Excon::Socket.new(datum)
474
464
  end
475
465
  end
476
466
 
@@ -573,6 +563,9 @@ module Excon
573
563
  if uri.user
574
564
  @data[:proxy][:user] = uri.user
575
565
  end
566
+ if @data[:ssl_proxy_headers] && !@data[:ssl_uri_schemes].include?(@data[:scheme])
567
+ raise ArgumentError, "The `:ssl_proxy_headers` parameter should only be used with HTTPS requests."
568
+ end
576
569
  if @data[:proxy][:scheme] == UNIX
577
570
  if @data[:proxy][:host]
578
571
  raise ArgumentError, "The `:host` parameter should not be set for `unix://` proxies.\n" +
@@ -99,6 +99,7 @@ module Excon
99
99
  :ssl_version,
100
100
  :ssl_min_version,
101
101
  :ssl_max_version,
102
+ :ssl_proxy_headers,
102
103
  :ssl_uri_schemes,
103
104
  :tcp_nodelay,
104
105
  :thread_safe_sockets,
@@ -40,7 +40,7 @@ module Excon
40
40
  end
41
41
  end
42
42
 
43
- logger.log(Logger::INFO, info) if info
43
+ logger.info(info) if info
44
44
 
45
45
  yield if block_given?
46
46
  end
@@ -104,6 +104,10 @@ module Excon
104
104
 
105
105
  request += "Proxy-Connection: Keep-Alive#{Excon::CR_NL}"
106
106
 
107
+ if @data[:ssl_proxy_headers]
108
+ request << Utils.headers_hash_to_s(@data[:ssl_proxy_headers])
109
+ end
110
+
107
111
  request += Excon::CR_NL
108
112
 
109
113
  # write out the proxy setup request
data/lib/excon/utils.rb CHANGED
@@ -121,5 +121,22 @@ module Excon
121
121
  str.gsub!(/\+/, ' ')
122
122
  str.gsub(ESCAPED) { $1.hex.chr }
123
123
  end
124
+
125
+ # Performs validation on the passed header hash and returns a string representation of the headers
126
+ def headers_hash_to_s(headers)
127
+ headers_str = String.new
128
+ headers.each do |key, values|
129
+ if key.to_s.match(/[\r\n]/)
130
+ raise Excon::Errors::InvalidHeaderKey.new(key.to_s.inspect + ' contains forbidden "\r" or "\n"')
131
+ end
132
+ [values].flatten.each do |value|
133
+ if value.to_s.match(/[\r\n]/)
134
+ raise Excon::Errors::InvalidHeaderValue.new(value.to_s.inspect + ' contains forbidden "\r" or "\n"')
135
+ end
136
+ headers_str << key.to_s << ': ' << value.to_s << CR_NL
137
+ end
138
+ end
139
+ headers_str
140
+ end
124
141
  end
125
142
  end
data/lib/excon/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Excon
3
- VERSION = '0.80.1'
3
+ VERSION = '0.81.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.80.1
4
+ version: 0.81.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dpiddy (Dan Peterson)
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-04-15 00:00:00.000000000 Z
13
+ date: 2021-04-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -265,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
265
  - !ruby/object:Gem::Version
266
266
  version: '0'
267
267
  requirements: []
268
- rubygems_version: 3.1.2
268
+ rubygems_version: 3.2.15
269
269
  signing_key:
270
270
  specification_version: 4
271
271
  summary: speed, persistence, http(s)