excon 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/excon/connection.rb +6 -6
- data/lib/excon/middlewares/capture_cookies.rb +1 -1
- data/lib/excon/middlewares/decompress.rb +4 -4
- data/lib/excon/middlewares/redirect_follower.rb +1 -1
- data/lib/excon/response.rb +4 -4
- data/lib/excon/utils.rb +8 -13
- data/lib/excon/version.rb +1 -1
- data/lib/excon.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cadb0fca5300321fa61bcdb57371355155c81328976a0f9e656e73b272e7b2c
|
4
|
+
data.tar.gz: 82fcc66b00fbda3159cab3153e8a084b68bf5c5fc193e5c2fb1b3eca511e8999
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 696637b0c1d203447e5b45ca73c7d5c97ed8dc2dea05c60873828b661c2d63f44a9c10b4970cc6ec79b9daa05abae603a5e015297c6c67046a8318c0768aa4e8
|
7
|
+
data.tar.gz: 62ec0190538e8ed8665e8f9bf95108d5acf9e3f6a4f7c71200dde2d6582c99fe444d9b6a2450c1f101d98ec784df4537fd677ed21744fd2d9c6d44b6fb5ef606
|
data/lib/excon/connection.rb
CHANGED
@@ -138,7 +138,7 @@ module Excon
|
|
138
138
|
|
139
139
|
# The HTTP spec isn't clear on it, but specifically, GET requests don't usually send bodies;
|
140
140
|
# if they don't, sending Content-Length:0 can cause issues.
|
141
|
-
unless datum[:method].to_s.casecmp('GET')
|
141
|
+
unless datum[:method].to_s.casecmp?('GET') && body.nil?
|
142
142
|
unless datum[:headers].has_key?('Content-Length')
|
143
143
|
datum[:headers]['Content-Length'] = detect_content_length(body)
|
144
144
|
end
|
@@ -250,7 +250,7 @@ module Excon
|
|
250
250
|
datum[:headers]['Authorization'] ||= 'Basic ' + ["#{user}:#{pass}"].pack('m').delete(Excon::CR_NL)
|
251
251
|
end
|
252
252
|
|
253
|
-
host_key = datum[:headers].keys.detect {|k| k.casecmp('Host')
|
253
|
+
host_key = datum[:headers].keys.detect {|k| k.casecmp?('Host') } || 'Host'
|
254
254
|
if datum[:scheme] == UNIX
|
255
255
|
datum[:headers][host_key] ||= ''
|
256
256
|
else
|
@@ -298,8 +298,8 @@ module Excon
|
|
298
298
|
@persistent_socket_reusable = true
|
299
299
|
|
300
300
|
if datum[:persistent]
|
301
|
-
if (key = datum[:response][:headers].keys.detect {|k| k.casecmp('Connection')
|
302
|
-
if datum[:response][:headers][key].casecmp('close')
|
301
|
+
if (key = datum[:response][:headers].keys.detect {|k| k.casecmp?('Connection') })
|
302
|
+
if datum[:response][:headers][key].casecmp?('close')
|
303
303
|
reset
|
304
304
|
end
|
305
305
|
end
|
@@ -338,8 +338,8 @@ module Excon
|
|
338
338
|
end
|
339
339
|
|
340
340
|
if @data[:persistent]
|
341
|
-
if (key = responses.last[:headers].keys.detect {|k| k.casecmp('Connection')
|
342
|
-
if responses.last[:headers][key].casecmp('close')
|
341
|
+
if (key = responses.last[:headers].keys.detect {|k| k.casecmp?('Connection') })
|
342
|
+
if responses.last[:headers][key].casecmp?('close')
|
343
343
|
reset
|
344
344
|
end
|
345
345
|
end
|
@@ -8,7 +8,7 @@ module Excon
|
|
8
8
|
|
9
9
|
def request_call(datum)
|
10
10
|
unless datum.key?(:response_block)
|
11
|
-
key = datum[:headers].keys.detect { |k| k.to_s.casecmp('Accept-Encoding')
|
11
|
+
key = datum[:headers].keys.detect { |k| k.to_s.casecmp?('Accept-Encoding') } || 'Accept-Encoding'
|
12
12
|
datum[:headers][key] = 'deflate, gzip' if datum[:headers][key].to_s.empty?
|
13
13
|
end
|
14
14
|
@stack.request_call(datum)
|
@@ -17,16 +17,16 @@ module Excon
|
|
17
17
|
def response_call(datum)
|
18
18
|
body = datum[:response][:body]
|
19
19
|
if !(datum.key?(:response_block) || body.nil? || body.empty?) &&
|
20
|
-
(key = datum[:response][:headers].keys.detect { |k| k.casecmp('Content-Encoding')
|
20
|
+
(key = datum[:response][:headers].keys.detect { |k| k.casecmp?('Content-Encoding') })
|
21
21
|
encodings = Utils.split_header_value(datum[:response][:headers][key])
|
22
|
-
if encodings
|
22
|
+
if encodings&.last&.casecmp?('deflate')
|
23
23
|
datum[:response][:body] = begin
|
24
24
|
Zlib::Inflate.new(INFLATE_ZLIB_OR_GZIP).inflate(body)
|
25
25
|
rescue Zlib::DataError # fallback to raw on error
|
26
26
|
Zlib::Inflate.new(INFLATE_RAW).inflate(body)
|
27
27
|
end
|
28
28
|
encodings.pop
|
29
|
-
elsif encodings
|
29
|
+
elsif encodings&.last&.casecmp?('gzip') || encodings&.last&.casecmp?('x-gzip')
|
30
30
|
datum[:response][:body] = Zlib::GzipReader.new(StringIO.new(body)).read
|
31
31
|
encodings.pop
|
32
32
|
end
|
data/lib/excon/response.rb
CHANGED
@@ -106,9 +106,9 @@ module Excon
|
|
106
106
|
|
107
107
|
unless (['HEAD', 'CONNECT'].include?(datum[:method].to_s.upcase)) || NO_ENTITY.include?(datum[:response][:status])
|
108
108
|
|
109
|
-
if (key = datum[:response][:headers].keys.detect {|k| k.casecmp('Transfer-Encoding')
|
109
|
+
if (key = datum[:response][:headers].keys.detect {|k| k.casecmp?('Transfer-Encoding') })
|
110
110
|
encodings = Utils.split_header_value(datum[:response][:headers][key])
|
111
|
-
if (encoding = encodings.last) && encoding.casecmp('chunked')
|
111
|
+
if (encoding = encodings.last) && encoding.casecmp?('chunked')
|
112
112
|
transfer_encoding_chunked = true
|
113
113
|
if encodings.length == 1
|
114
114
|
datum[:response][:headers].delete(key)
|
@@ -156,7 +156,7 @@ module Excon
|
|
156
156
|
end
|
157
157
|
parse_headers(socket, datum) # merge trailers into headers
|
158
158
|
else
|
159
|
-
if (key = datum[:response][:headers].keys.detect {|k| k.casecmp('Content-Length')
|
159
|
+
if (key = datum[:response][:headers].keys.detect {|k| k.casecmp?('Content-Length') })
|
160
160
|
content_length = datum[:response][:headers][key].to_i
|
161
161
|
end
|
162
162
|
|
@@ -202,7 +202,7 @@ module Excon
|
|
202
202
|
raise Excon::Error::ResponseParse, 'malformed header' unless value
|
203
203
|
# add key/value or append value to existing values
|
204
204
|
datum[:response][:headers][key] = ([datum[:response][:headers][key]] << value.strip).compact.join(', ')
|
205
|
-
if key.casecmp('Set-Cookie')
|
205
|
+
if key.casecmp?('Set-Cookie')
|
206
206
|
datum[:response][:cookies] << value.strip
|
207
207
|
end
|
208
208
|
last_key = key
|
data/lib/excon/utils.rb
CHANGED
@@ -69,26 +69,21 @@ module Excon
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
params = {}
|
72
|
+
def split_query_string(string)
|
73
|
+
query = {}
|
75
74
|
|
76
75
|
string.split(/[&;] */n).each do |pair|
|
77
|
-
key, value = pair.split('=', 2)
|
78
|
-
|
79
|
-
params[key] = if params[key]
|
80
|
-
[params[key], value].flatten
|
81
|
-
else
|
82
|
-
value
|
83
|
-
end
|
76
|
+
key, value = pair.split('=', 2)
|
77
|
+
query[key] = query[key] ? [query[key], value].flatten : value
|
84
78
|
end
|
85
79
|
|
86
|
-
|
80
|
+
query
|
87
81
|
end
|
88
82
|
|
89
83
|
def default_port?(datum)
|
90
|
-
(datum[:scheme]
|
91
|
-
(datum[:scheme]
|
84
|
+
(!datum[:scheme]&.casecmp?('unix') && datum[:port].nil?) ||
|
85
|
+
(datum[:scheme]&.casecmp?('http') && datum[:port] == 80) ||
|
86
|
+
(datum[:scheme]&.casecmp?('https') && datum[:port] == 443)
|
92
87
|
end
|
93
88
|
|
94
89
|
def query_string(datum)
|
data/lib/excon/version.rb
CHANGED
data/lib/excon.rb
CHANGED
@@ -163,7 +163,7 @@ module Excon
|
|
163
163
|
request_params[:headers] = headers
|
164
164
|
end
|
165
165
|
if request_params.key?(:query) && request_params[:query].instance_of?(String)
|
166
|
-
request_params[:query] = Utils.
|
166
|
+
request_params[:query] = Utils.split_query_string(request_params[:query])
|
167
167
|
end
|
168
168
|
if block_given?
|
169
169
|
raise(ArgumentError, 'stub requires either response_params OR a block') if response_params
|
@@ -186,7 +186,7 @@ module Excon
|
|
186
186
|
request_params[:method] = method.to_s.downcase.to_sym
|
187
187
|
end
|
188
188
|
if request_params.key?(:query) && request_params[:query].instance_of?(String)
|
189
|
-
request_params[:query] = Utils.
|
189
|
+
request_params[:query] = Utils.split_query_string(request_params[:query])
|
190
190
|
end
|
191
191
|
Excon.stubs.each do |stub, response_params|
|
192
192
|
captures = { headers: {} }
|
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: 1.
|
4
|
+
version: 1.1.1
|
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: 2024-10-
|
13
|
+
date: 2024-10-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|