httparty 0.21.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +3 -6
- data/Changelog.md +385 -318
- data/httparty.gemspec +2 -1
- data/lib/httparty/connection_adapter.rb +5 -24
- data/lib/httparty/logger/logstash_formatter.rb +1 -0
- data/lib/httparty/module_inheritable_attributes.rb +3 -5
- data/lib/httparty/parser.rb +3 -0
- data/lib/httparty/request/body.rb +1 -0
- data/lib/httparty/request.rb +34 -19
- data/lib/httparty/response.rb +3 -3
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +13 -10
- data/script/release +4 -4
- metadata +18 -3
data/httparty.gemspec
CHANGED
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = 'Makes http fun! Also, makes consuming restful web services dead easy.'
|
14
14
|
s.description = 'Makes http fun! Also, makes consuming restful web services dead easy.'
|
15
15
|
|
16
|
-
s.required_ruby_version = '>= 2.
|
16
|
+
s.required_ruby_version = '>= 2.7.0'
|
17
17
|
|
18
|
+
s.add_dependency 'csv'
|
18
19
|
s.add_dependency 'multi_xml', ">= 0.5.2"
|
19
20
|
s.add_dependency 'mini_mime', ">= 1.0.0"
|
20
21
|
|
@@ -119,10 +119,7 @@ module HTTParty
|
|
119
119
|
if add_timeout?(options[:timeout])
|
120
120
|
http.open_timeout = options[:timeout]
|
121
121
|
http.read_timeout = options[:timeout]
|
122
|
-
|
123
|
-
from_ruby_version('2.6.0', option: :write_timeout, warn: false) do
|
124
|
-
http.write_timeout = options[:timeout]
|
125
|
-
end
|
122
|
+
http.write_timeout = options[:timeout]
|
126
123
|
end
|
127
124
|
|
128
125
|
if add_timeout?(options[:read_timeout])
|
@@ -134,15 +131,11 @@ module HTTParty
|
|
134
131
|
end
|
135
132
|
|
136
133
|
if add_timeout?(options[:write_timeout])
|
137
|
-
|
138
|
-
http.write_timeout = options[:write_timeout]
|
139
|
-
end
|
134
|
+
http.write_timeout = options[:write_timeout]
|
140
135
|
end
|
141
136
|
|
142
137
|
if add_max_retries?(options[:max_retries])
|
143
|
-
|
144
|
-
http.max_retries = options[:max_retries]
|
145
|
-
end
|
138
|
+
http.max_retries = options[:max_retries]
|
146
139
|
end
|
147
140
|
|
148
141
|
if options[:debug_output]
|
@@ -157,15 +150,11 @@ module HTTParty
|
|
157
150
|
#
|
158
151
|
# @see https://bugs.ruby-lang.org/issues/6617
|
159
152
|
if options[:local_host]
|
160
|
-
|
161
|
-
http.local_host = options[:local_host]
|
162
|
-
end
|
153
|
+
http.local_host = options[:local_host]
|
163
154
|
end
|
164
155
|
|
165
156
|
if options[:local_port]
|
166
|
-
|
167
|
-
http.local_port = options[:local_port]
|
168
|
-
end
|
157
|
+
http.local_port = options[:local_port]
|
169
158
|
end
|
170
159
|
|
171
160
|
http
|
@@ -173,14 +162,6 @@ module HTTParty
|
|
173
162
|
|
174
163
|
private
|
175
164
|
|
176
|
-
def from_ruby_version(ruby_version, option: nil, warn: true)
|
177
|
-
if RUBY_VERSION >= ruby_version
|
178
|
-
yield
|
179
|
-
elsif warn
|
180
|
-
Kernel.warn("Warning: option #{ option } requires Ruby version #{ ruby_version } or later")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
165
|
def add_timeout?(timeout)
|
185
166
|
timeout && (timeout.is_a?(Integer) || timeout.is_a?(Float))
|
186
167
|
end
|
@@ -29,7 +29,7 @@ module HTTParty
|
|
29
29
|
@mattr_inheritable_attrs += args
|
30
30
|
|
31
31
|
args.each do |arg|
|
32
|
-
|
32
|
+
singleton_class.attr_accessor(arg)
|
33
33
|
end
|
34
34
|
|
35
35
|
@mattr_inheritable_attrs
|
@@ -42,14 +42,12 @@ module HTTParty
|
|
42
42
|
subclass.instance_variable_set(ivar, instance_variable_get(ivar).clone)
|
43
43
|
|
44
44
|
if instance_variable_get(ivar).respond_to?(:merge)
|
45
|
-
|
45
|
+
subclass.class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
46
46
|
def self.#{inheritable_attribute}
|
47
47
|
duplicate = ModuleInheritableAttributes.hash_deep_dup(#{ivar})
|
48
48
|
#{ivar} = superclass.#{inheritable_attribute}.merge(duplicate)
|
49
49
|
end
|
50
|
-
|
51
|
-
|
52
|
-
subclass.class_eval method
|
50
|
+
RUBY
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
data/lib/httparty/parser.rb
CHANGED
@@ -118,16 +118,19 @@ module HTTParty
|
|
118
118
|
protected
|
119
119
|
|
120
120
|
def xml
|
121
|
+
require 'multi_xml'
|
121
122
|
MultiXml.parse(body)
|
122
123
|
end
|
123
124
|
|
124
125
|
UTF8_BOM = "\xEF\xBB\xBF"
|
125
126
|
|
126
127
|
def json
|
128
|
+
require 'json'
|
127
129
|
JSON.parse(body, :quirks_mode => true, :allow_nan => true)
|
128
130
|
end
|
129
131
|
|
130
132
|
def csv
|
133
|
+
require 'csv'
|
131
134
|
CSV.parse(body)
|
132
135
|
end
|
133
136
|
|
data/lib/httparty/request.rb
CHANGED
@@ -295,24 +295,7 @@ module HTTParty
|
|
295
295
|
|
296
296
|
def handle_response(raw_body, &block)
|
297
297
|
if response_redirects?
|
298
|
-
|
299
|
-
if options[:logger]
|
300
|
-
logger = HTTParty::Logger.build(options[:logger], options[:log_level], options[:log_format])
|
301
|
-
logger.format(self, last_response)
|
302
|
-
end
|
303
|
-
self.path = last_response['location']
|
304
|
-
self.redirect = true
|
305
|
-
if last_response.class == Net::HTTPSeeOther
|
306
|
-
unless options[:maintain_method_across_redirects] && options[:resend_on_redirect]
|
307
|
-
self.http_method = Net::HTTP::Get
|
308
|
-
end
|
309
|
-
elsif last_response.code != '307' && last_response.code != '308'
|
310
|
-
unless options[:maintain_method_across_redirects]
|
311
|
-
self.http_method = Net::HTTP::Get
|
312
|
-
end
|
313
|
-
end
|
314
|
-
capture_cookies(last_response)
|
315
|
-
perform(&block)
|
298
|
+
handle_redirection(&block)
|
316
299
|
else
|
317
300
|
raw_body ||= last_response.body
|
318
301
|
|
@@ -331,10 +314,34 @@ module HTTParty
|
|
331
314
|
end
|
332
315
|
end
|
333
316
|
|
317
|
+
def handle_redirection(&block)
|
318
|
+
options[:limit] -= 1
|
319
|
+
if options[:logger]
|
320
|
+
logger = HTTParty::Logger.build(options[:logger], options[:log_level], options[:log_format])
|
321
|
+
logger.format(self, last_response)
|
322
|
+
end
|
323
|
+
self.path = last_response['location']
|
324
|
+
self.redirect = true
|
325
|
+
if last_response.class == Net::HTTPSeeOther
|
326
|
+
unless options[:maintain_method_across_redirects] && options[:resend_on_redirect]
|
327
|
+
self.http_method = Net::HTTP::Get
|
328
|
+
end
|
329
|
+
elsif last_response.code != '307' && last_response.code != '308'
|
330
|
+
unless options[:maintain_method_across_redirects]
|
331
|
+
self.http_method = Net::HTTP::Get
|
332
|
+
end
|
333
|
+
end
|
334
|
+
if http_method == Net::HTTP::Get
|
335
|
+
clear_body
|
336
|
+
end
|
337
|
+
capture_cookies(last_response)
|
338
|
+
perform(&block)
|
339
|
+
end
|
340
|
+
|
334
341
|
def handle_host_redirection
|
335
342
|
check_duplicate_location_header
|
336
343
|
redirect_path = options[:uri_adapter].parse(last_response['location']).normalize
|
337
|
-
return if redirect_path.relative? || path.host == redirect_path.host
|
344
|
+
return if redirect_path.relative? || path.host == redirect_path.host || uri.host == redirect_path.host
|
338
345
|
@changed_hosts = true
|
339
346
|
end
|
340
347
|
|
@@ -362,6 +369,14 @@ module HTTParty
|
|
362
369
|
parser.call(body, format)
|
363
370
|
end
|
364
371
|
|
372
|
+
# Some Web Application Firewalls reject incoming GET requests that have a body
|
373
|
+
# if we redirect, and the resulting verb is GET then we will clear the body that
|
374
|
+
# may be left behind from the initiating request
|
375
|
+
def clear_body
|
376
|
+
options[:body] = nil
|
377
|
+
@raw_request.body = nil
|
378
|
+
end
|
379
|
+
|
365
380
|
def capture_cookies(response)
|
366
381
|
return unless response['Set-Cookie']
|
367
382
|
cookies_hash = HTTParty::CookieHash.new
|
data/lib/httparty/response.rb
CHANGED
@@ -67,12 +67,12 @@ module HTTParty
|
|
67
67
|
end
|
68
68
|
|
69
69
|
# Support old multiple_choice? method from pre 2.0.0 era.
|
70
|
-
if ::
|
70
|
+
if ::RUBY_PLATFORM != 'java'
|
71
71
|
alias_method :multiple_choice?, :multiple_choices?
|
72
72
|
end
|
73
73
|
|
74
74
|
# Support old status codes method from pre 2.6.0 era.
|
75
|
-
if ::
|
75
|
+
if ::RUBY_PLATFORM != 'java'
|
76
76
|
alias_method :gateway_time_out?, :gateway_timeout?
|
77
77
|
alias_method :request_entity_too_large?, :payload_too_large?
|
78
78
|
alias_method :request_time_out?, :request_timeout?
|
@@ -133,7 +133,7 @@ module HTTParty
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def throw_exception
|
136
|
-
if @request.options[:raise_on]
|
136
|
+
if @request.options[:raise_on].to_a.detect { |c| code.to_s.match(/#{c.to_s}/) }
|
137
137
|
::Kernel.raise ::HTTParty::ResponseError.new(@response), "Code #{code} - #{body}"
|
138
138
|
end
|
139
139
|
end
|
data/lib/httparty/version.rb
CHANGED
data/lib/httparty.rb
CHANGED
@@ -3,11 +3,6 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'net/http'
|
5
5
|
require 'uri'
|
6
|
-
require 'zlib'
|
7
|
-
require 'multi_xml'
|
8
|
-
require 'mini_mime'
|
9
|
-
require 'json'
|
10
|
-
require 'csv'
|
11
6
|
|
12
7
|
require 'httparty/module_inheritable_attributes'
|
13
8
|
require 'httparty/cookie_hash'
|
@@ -83,7 +78,7 @@ module HTTParty
|
|
83
78
|
#
|
84
79
|
# class Foo
|
85
80
|
# include HTTParty
|
86
|
-
# raise_on [404, 500]
|
81
|
+
# raise_on [404, 500, '5[0-9]*']
|
87
82
|
# end
|
88
83
|
def raise_on(codes = [])
|
89
84
|
default_options[:raise_on] = *codes
|
@@ -591,6 +586,13 @@ module HTTParty
|
|
591
586
|
perform_request Net::HTTP::Unlock, path, options, &block
|
592
587
|
end
|
593
588
|
|
589
|
+
def build_request(http_method, path, options = {})
|
590
|
+
options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
|
591
|
+
HeadersProcessor.new(headers, options).call
|
592
|
+
process_cookies(options)
|
593
|
+
Request.new(http_method, path, options)
|
594
|
+
end
|
595
|
+
|
594
596
|
attr_reader :default_options
|
595
597
|
|
596
598
|
private
|
@@ -606,10 +608,7 @@ module HTTParty
|
|
606
608
|
end
|
607
609
|
|
608
610
|
def perform_request(http_method, path, options, &block) #:nodoc:
|
609
|
-
|
610
|
-
HeadersProcessor.new(headers, options).call
|
611
|
-
process_cookies(options)
|
612
|
-
Request.new(http_method, path, options).perform(&block)
|
611
|
+
build_request(http_method, path, options).perform(&block)
|
613
612
|
end
|
614
613
|
|
615
614
|
def process_cookies(options) #:nodoc:
|
@@ -676,6 +675,10 @@ module HTTParty
|
|
676
675
|
def self.options(*args, &block)
|
677
676
|
Basement.options(*args, &block)
|
678
677
|
end
|
678
|
+
|
679
|
+
def self.build_request(*args, &block)
|
680
|
+
Basement.build_request(*args, &block)
|
681
|
+
end
|
679
682
|
end
|
680
683
|
|
681
684
|
require 'httparty/hash_conversions'
|
data/script/release
CHANGED
@@ -18,9 +18,9 @@ gem_name=httparty
|
|
18
18
|
rm -rf $gem_name-*.gem
|
19
19
|
gem build -q $gem_name.gemspec
|
20
20
|
|
21
|
-
# Make sure we're on the
|
22
|
-
(git branch | grep -q '*
|
23
|
-
echo "Only release from the
|
21
|
+
# Make sure we're on the main branch.
|
22
|
+
(git branch | grep -q '* main') || {
|
23
|
+
echo "Only release from the main branch."
|
24
24
|
exit 1
|
25
25
|
}
|
26
26
|
|
@@ -39,4 +39,4 @@ git fetch -t origin
|
|
39
39
|
|
40
40
|
# Tag it and bag it.
|
41
41
|
gem push $gem_name-*.gem && git tag "$tag" &&
|
42
|
-
git push origin
|
42
|
+
git push origin main && git push origin "$tag"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,8 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: csv
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: multi_xml
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,6 +62,7 @@ extensions: []
|
|
48
62
|
extra_rdoc_files: []
|
49
63
|
files:
|
50
64
|
- ".editorconfig"
|
65
|
+
- ".github/dependabot.yml"
|
51
66
|
- ".github/workflows/ci.yml"
|
52
67
|
- ".gitignore"
|
53
68
|
- ".rubocop.yml"
|
@@ -123,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
138
|
requirements:
|
124
139
|
- - ">="
|
125
140
|
- !ruby/object:Gem::Version
|
126
|
-
version: 2.
|
141
|
+
version: 2.7.0
|
127
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
143
|
requirements:
|
129
144
|
- - ">="
|