httparty 0.24.3 → 0.25.0
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 +4 -4
- data/CONTRIBUTING.md +2 -4
- data/Rakefile +3 -1
- data/bin/httparty +32 -11
- data/docs/README.md +38 -4
- data/examples/README.md +12 -23
- data/examples/basic.rb +2 -2
- data/examples/basic_auth.rb +19 -0
- data/examples/cookies.rb +20 -0
- data/examples/crack.rb +2 -2
- data/examples/custom_parsers.rb +2 -2
- data/examples/debug_output.rb +17 -0
- data/examples/google.rb +2 -2
- data/examples/headers_and_user_agents.rb +2 -2
- data/examples/idn.rb +4 -3
- data/examples/logging.rb +2 -2
- data/examples/nokogiri_html_parser.rb +2 -2
- data/examples/party_foul_mode.rb +1 -0
- data/examples/peer_cert.rb +2 -2
- data/examples/rescue_json.rb +5 -3
- data/examples/stackexchange.rb +2 -2
- data/examples/stream_download.rb +2 -2
- data/examples/whoismyrep.rb +2 -2
- data/httparty.gemspec +2 -1
- data/lib/httparty/connection_adapter.rb +6 -6
- data/lib/httparty/cookie_hash.rb +1 -1
- data/lib/httparty/headers_processor.rb +5 -2
- data/lib/httparty/logger/curl_formatter.rb +16 -3
- data/lib/httparty/logger/logger.rb +2 -1
- data/lib/httparty/module_inheritable_attributes.rb +13 -13
- data/lib/httparty/net_digest_auth.rb +9 -11
- data/lib/httparty/parser.rb +2 -1
- data/lib/httparty/request/body.rb +5 -3
- data/lib/httparty/request/streaming_multipart_body.rb +9 -2
- data/lib/httparty/request.rb +31 -15
- data/lib/httparty/response.rb +16 -4
- data/lib/httparty/text_encoder.rb +1 -5
- data/lib/httparty/utils.rb +1 -5
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +30 -18
- metadata +8 -18
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/ci.yml +0 -24
- data/.rubocop.yml +0 -92
- data/.rubocop_todo.yml +0 -124
- data/Gemfile +0 -27
- data/Guardfile +0 -17
- data/cucumber.yml +0 -1
- data/examples/aaws.rb +0 -36
- data/examples/delicious.rb +0 -37
- data/examples/rubyurl.rb +0 -14
- data/examples/tripit_sign_in.rb +0 -44
- data/examples/twitter.rb +0 -31
- data/script/release +0 -42
- data/website/css/common.css +0 -47
- data/website/index.html +0 -73
|
@@ -7,20 +7,20 @@ module HTTParty
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
# borrowed from Rails 3.2 ActiveSupport
|
|
10
|
-
def self.hash_deep_dup(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if value.is_a?(Hash)
|
|
10
|
+
def self.hash_deep_dup(object)
|
|
11
|
+
case object
|
|
12
|
+
when Hash
|
|
13
|
+
object.each_with_object(object.dup) do |(key, value), duplicate|
|
|
15
14
|
duplicate[key] = hash_deep_dup(value)
|
|
16
|
-
elsif value.is_a?(Proc)
|
|
17
|
-
duplicate[key] = value.dup
|
|
18
|
-
else
|
|
19
|
-
duplicate[key] = value
|
|
20
15
|
end
|
|
16
|
+
when Array
|
|
17
|
+
copy = object.dup.map! { |value| hash_deep_dup(value) }
|
|
18
|
+
object.frozen? ? copy.freeze : copy
|
|
19
|
+
when Proc
|
|
20
|
+
object.dup
|
|
21
|
+
else
|
|
22
|
+
object
|
|
21
23
|
end
|
|
22
|
-
|
|
23
|
-
duplicate
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
module ClassMethods #:nodoc:
|
|
@@ -44,8 +44,8 @@ module HTTParty
|
|
|
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
|
-
duplicate =
|
|
48
|
-
#{ivar} =
|
|
47
|
+
duplicate = superclass.#{inheritable_attribute}.merge(#{ivar})
|
|
48
|
+
#{ivar} = ModuleInheritableAttributes.hash_deep_dup(duplicate)
|
|
49
49
|
end
|
|
50
50
|
RUBY
|
|
51
51
|
end
|
|
@@ -18,8 +18,9 @@ module Net
|
|
|
18
18
|
add_field('Authorization', v)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Net::HTTP joins repeated fields with ", ", but cookies are split by "; ".
|
|
21
22
|
authenticator.cookie_header.each do |v|
|
|
22
|
-
|
|
23
|
+
self['Cookie'] = [self['Cookie'], v].compact.join('; ')
|
|
23
24
|
end
|
|
24
25
|
end
|
|
25
26
|
|
|
@@ -72,20 +73,17 @@ module Net
|
|
|
72
73
|
non_quoted = $1.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
|
|
73
74
|
non_quoted.gsub(/(\w+)=([^,]*)/) { params[$1] = $2 }
|
|
74
75
|
end
|
|
76
|
+
# The server can offer a list, but the client has to answer with one.
|
|
77
|
+
params['qop'] = 'auth' if params['qop'].to_s.split(',').map(&:strip).include?('auth')
|
|
75
78
|
params
|
|
76
79
|
end
|
|
77
80
|
|
|
81
|
+
# Send back each cookie's name=value only. Attributes like Path and
|
|
82
|
+
# HttpOnly are for the client, and cookies share one header, split by "; ".
|
|
78
83
|
def parse_cookies(response_header)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
cookies
|
|
82
|
-
|
|
83
|
-
cookies.reduce([]) do |ret, cookie|
|
|
84
|
-
ret << cookie
|
|
85
|
-
ret
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
cookies
|
|
84
|
+
set_cookies = response_header.respond_to?(:get_fields) ? response_header.get_fields('Set-Cookie') : response_header['Set-Cookie']
|
|
85
|
+
cookies = Array(set_cookies).map { |cookie| cookie.split(';', 2).first.to_s.strip }.reject(&:empty?)
|
|
86
|
+
cookies.empty? ? [] : [cookies.join('; ')]
|
|
89
87
|
end
|
|
90
88
|
|
|
91
89
|
def opaque_present?
|
data/lib/httparty/parser.rb
CHANGED
|
@@ -80,7 +80,8 @@ module HTTParty
|
|
|
80
80
|
# @return [Symbol]
|
|
81
81
|
# @return [nil] mime type not supported
|
|
82
82
|
def self.format_from_mimetype(mimetype)
|
|
83
|
-
|
|
83
|
+
mimetype = mimetype.downcase
|
|
84
|
+
formats[formats.keys.detect {|k| mimetype.include?(k.downcase)}]
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
# @return [Array<Symbol>] list of supported formats
|
|
@@ -41,7 +41,7 @@ module HTTParty
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def prepared_parts
|
|
44
|
-
normalized_params = params.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
|
|
44
|
+
normalized_params = params.to_hash.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
|
|
45
45
|
normalized_params.map do |key, value|
|
|
46
46
|
[key, value, file?(value)]
|
|
47
47
|
end
|
|
@@ -57,7 +57,7 @@ module HTTParty
|
|
|
57
57
|
}.freeze
|
|
58
58
|
|
|
59
59
|
def generate_multipart
|
|
60
|
-
normalized_params = params.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
|
|
60
|
+
normalized_params = params.to_hash.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
|
|
61
61
|
|
|
62
62
|
multipart = normalized_params.inject(''.b) do |memo, (key, value)|
|
|
63
63
|
memo << "--#{boundary}#{NEWLINE}".b
|
|
@@ -91,7 +91,9 @@ module HTTParty
|
|
|
91
91
|
|
|
92
92
|
def normalize_query(query)
|
|
93
93
|
if query_string_normalizer
|
|
94
|
-
|
|
94
|
+
# Normalizers may return an array of pairs, which the query string joins with '&'
|
|
95
|
+
normalized = query_string_normalizer.call(query)
|
|
96
|
+
normalized.respond_to?(:to_ary) ? normalized.to_ary.join('&') : normalized
|
|
95
97
|
else
|
|
96
98
|
HashConversions.to_params(query)
|
|
97
99
|
end
|
|
@@ -15,6 +15,7 @@ module HTTParty
|
|
|
15
15
|
@header_buffer = nil
|
|
16
16
|
@header_offset = 0
|
|
17
17
|
@footer_sent = false
|
|
18
|
+
@read_buffer = ''.b
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def size
|
|
@@ -27,9 +28,11 @@ module HTTParty
|
|
|
27
28
|
return read_all(outbuf) if length.nil?
|
|
28
29
|
|
|
29
30
|
while outbuf.bytesize < length
|
|
30
|
-
|
|
31
|
+
remaining = length - outbuf.bytesize
|
|
32
|
+
chunk = @read_buffer.empty? ? read_chunk(remaining) : @read_buffer
|
|
31
33
|
break if chunk.nil?
|
|
32
|
-
outbuf << chunk
|
|
34
|
+
outbuf << chunk.byteslice(0, remaining)
|
|
35
|
+
@read_buffer = chunk.byteslice(remaining..-1) || ''.b
|
|
33
36
|
end
|
|
34
37
|
|
|
35
38
|
outbuf.empty? ? nil : outbuf
|
|
@@ -42,6 +45,7 @@ module HTTParty
|
|
|
42
45
|
@header_buffer = nil
|
|
43
46
|
@header_offset = 0
|
|
44
47
|
@footer_sent = false
|
|
48
|
+
@read_buffer = ''.b
|
|
45
49
|
@parts.each do |_key, value, _is_file|
|
|
46
50
|
value.rewind if value.respond_to?(:rewind)
|
|
47
51
|
end
|
|
@@ -50,6 +54,8 @@ module HTTParty
|
|
|
50
54
|
private
|
|
51
55
|
|
|
52
56
|
def read_all(outbuf)
|
|
57
|
+
outbuf << @read_buffer
|
|
58
|
+
@read_buffer = ''.b
|
|
53
59
|
while (chunk = read_chunk(CHUNK_SIZE))
|
|
54
60
|
outbuf << chunk
|
|
55
61
|
end
|
|
@@ -110,6 +116,7 @@ module HTTParty
|
|
|
110
116
|
if chunk
|
|
111
117
|
return chunk
|
|
112
118
|
else
|
|
119
|
+
value.rewind if value.respond_to?(:rewind)
|
|
113
120
|
@current_file = nil
|
|
114
121
|
@state = :newline
|
|
115
122
|
return nil
|
data/lib/httparty/request.rb
CHANGED
|
@@ -81,8 +81,15 @@ module HTTParty
|
|
|
81
81
|
|
|
82
82
|
@path = if uri.is_a?(uri_adapter)
|
|
83
83
|
uri
|
|
84
|
-
elsif String.try_convert(uri)
|
|
85
|
-
|
|
84
|
+
elsif (uri_str = String.try_convert(uri))
|
|
85
|
+
# Normalizing an empty path ("", "?query" or "#fragment") with the
|
|
86
|
+
# default URI adapter turns it into "/", which appends an unwanted
|
|
87
|
+
# trailing slash to the base_uri path (breaking e.g. SOAP endpoints).
|
|
88
|
+
# Such a reference means the base_uri itself (RFC 3986 section 5.2.2),
|
|
89
|
+
# so leave it alone and let the uri adapter normalize everything else.
|
|
90
|
+
# See https://github.com/jnunemaker/httparty/issues/742
|
|
91
|
+
parsed_uri = uri_adapter.parse(uri_str)
|
|
92
|
+
empty_path_reference?(parsed_uri) ? parsed_uri : parsed_uri.normalize
|
|
86
93
|
else
|
|
87
94
|
raise ArgumentError,
|
|
88
95
|
"bad argument (expected #{uri_adapter} object or URI string)"
|
|
@@ -93,16 +100,17 @@ module HTTParty
|
|
|
93
100
|
if uri.respond_to? :request_uri
|
|
94
101
|
uri.request_uri
|
|
95
102
|
else
|
|
96
|
-
uri.path
|
|
103
|
+
uri.query ? "#{uri.path}?#{uri.query}" : uri.path
|
|
97
104
|
end
|
|
98
105
|
end
|
|
99
106
|
|
|
100
107
|
def uri
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
# Resolve a relative redirect Location ("baz", "../baz", "?page=2", "")
|
|
109
|
+
# against the URL that redirected (RFC 3986 section 5.2). Keep it as an
|
|
110
|
+
# absolute path so later calls resolve it to the same URL. A Location
|
|
111
|
+
# with a host is used as given below.
|
|
112
|
+
if redirect && path.relative? && path.host.nil?
|
|
113
|
+
@path = options[:uri_adapter].parse(request_uri((@last_uri + path).normalize))
|
|
106
114
|
end
|
|
107
115
|
|
|
108
116
|
if path.relative? && path.host
|
|
@@ -171,7 +179,7 @@ module HTTParty
|
|
|
171
179
|
end
|
|
172
180
|
|
|
173
181
|
handle_host_redirection if response_redirects?
|
|
174
|
-
result = handle_unauthorized
|
|
182
|
+
result = handle_unauthorized(&block)
|
|
175
183
|
result ||= handle_response(chunked_body, &block)
|
|
176
184
|
result
|
|
177
185
|
rescue *COMMON_NETWORK_ERRORS => e
|
|
@@ -191,9 +199,7 @@ module HTTParty
|
|
|
191
199
|
end
|
|
192
200
|
|
|
193
201
|
def _dump(_level)
|
|
194
|
-
opts = options.
|
|
195
|
-
opts.delete(:logger)
|
|
196
|
-
opts.delete(:parser) if opts[:parser] && opts[:parser].is_a?(Proc)
|
|
202
|
+
opts = options.reject { |key, value| value.is_a?(Proc) || %i[logger debug_output].include?(key) }
|
|
197
203
|
Marshal.dump([http_method, path, opts, last_response, @last_uri, @raw_request])
|
|
198
204
|
end
|
|
199
205
|
|
|
@@ -335,10 +341,14 @@ module HTTParty
|
|
|
335
341
|
logger = HTTParty::Logger.build(options[:logger], options[:log_level], options[:log_format])
|
|
336
342
|
logger.format(self, last_response)
|
|
337
343
|
end
|
|
338
|
-
|
|
344
|
+
# A relative Location is resolved against the current URL in #uri, so
|
|
345
|
+
# it isn't normalized first: Addressable would drop the "../" in it.
|
|
346
|
+
location = options[:uri_adapter].parse(last_response['location'])
|
|
347
|
+
self.path = location.relative? && location.host.nil? ? location : location.normalize
|
|
339
348
|
self.redirect = true
|
|
340
349
|
if last_response.class == Net::HTTPSeeOther
|
|
341
|
-
|
|
350
|
+
# A 303 turns the request into a GET, but a HEAD stays a HEAD (RFC 9110)
|
|
351
|
+
unless options[:maintain_method_across_redirects] && (options[:resend_on_redirect] || http_method == Net::HTTP::Head)
|
|
342
352
|
self.http_method = Net::HTTP::Get
|
|
343
353
|
end
|
|
344
354
|
elsif last_response.code != '307' && last_response.code != '308'
|
|
@@ -413,7 +423,7 @@ module HTTParty
|
|
|
413
423
|
|
|
414
424
|
def validate
|
|
415
425
|
raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0
|
|
416
|
-
raise ArgumentError,
|
|
426
|
+
raise ArgumentError, "only #{SupportedHTTPMethods.map { |m| m::METHOD.downcase }.join(', ')} methods are supported" unless SupportedHTTPMethods.include?(http_method)
|
|
417
427
|
raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].respond_to?(:to_hash)
|
|
418
428
|
raise ArgumentError, 'only one authentication method, :basic_auth or :digest_auth may be used at a time' if options[:basic_auth] && options[:digest_auth]
|
|
419
429
|
raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].respond_to?(:to_hash)
|
|
@@ -445,6 +455,12 @@ module HTTParty
|
|
|
445
455
|
).call
|
|
446
456
|
end
|
|
447
457
|
|
|
458
|
+
# A reference with no scheme, host or path ("", "?query" or "#fragment")
|
|
459
|
+
# refers to the base URI itself (RFC 3986 section 5.2.2).
|
|
460
|
+
def empty_path_reference?(uri)
|
|
461
|
+
uri.scheme.nil? && uri.host.nil? && uri.path.to_s.empty?
|
|
462
|
+
end
|
|
463
|
+
|
|
448
464
|
def validate_uri_safety!(new_uri)
|
|
449
465
|
return if options[:skip_uri_validation]
|
|
450
466
|
|
data/lib/httparty/response.rb
CHANGED
|
@@ -34,7 +34,8 @@ module HTTParty
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def parsed_response
|
|
37
|
-
@parsed_response
|
|
37
|
+
return @parsed_response if defined?(@parsed_response)
|
|
38
|
+
@parsed_response = @parsed_block.call
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
def code
|
|
@@ -52,7 +53,7 @@ module HTTParty
|
|
|
52
53
|
|
|
53
54
|
def inspect
|
|
54
55
|
inspect_id = ::Kernel::format '%x', (object_id * 2)
|
|
55
|
-
%(#<#{self.class}:0x#{inspect_id}
|
|
56
|
+
%(#<#{self.class}:0x#{inspect_id} #{inspect_parsed_response}, @response=#{response.inspect}, @headers=#{headers.inspect}>)
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
CODES_TO_OBJ = ::Net::HTTPResponse::CODE_CLASS_TO_OBJ.merge ::Net::HTTPResponse::CODE_TO_OBJ
|
|
@@ -94,8 +95,12 @@ module HTTParty
|
|
|
94
95
|
end
|
|
95
96
|
|
|
96
97
|
def pretty_print(pp)
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
parsed = parsed_response
|
|
99
|
+
rescue StandardError
|
|
100
|
+
super
|
|
101
|
+
else
|
|
102
|
+
if !parsed.nil? && parsed.respond_to?(:pretty_print)
|
|
103
|
+
parsed.pretty_print(pp)
|
|
99
104
|
else
|
|
100
105
|
super
|
|
101
106
|
end
|
|
@@ -145,6 +150,13 @@ module HTTParty
|
|
|
145
150
|
|
|
146
151
|
private
|
|
147
152
|
|
|
153
|
+
# Debugging output must not raise, so show a parse error and the raw body.
|
|
154
|
+
def inspect_parsed_response
|
|
155
|
+
"parsed_response=#{parsed_response.inspect}"
|
|
156
|
+
rescue StandardError => e
|
|
157
|
+
"parsed_response=#<#{e.class}: #{e.message.inspect}>, body=#{body.inspect}"
|
|
158
|
+
end
|
|
159
|
+
|
|
148
160
|
def code_matches?(matcher)
|
|
149
161
|
case matcher
|
|
150
162
|
when Range
|
|
@@ -11,7 +11,7 @@ module HTTParty
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def call
|
|
14
|
-
if
|
|
14
|
+
if charset
|
|
15
15
|
encoded_text
|
|
16
16
|
else
|
|
17
17
|
text
|
|
@@ -20,10 +20,6 @@ module HTTParty
|
|
|
20
20
|
|
|
21
21
|
private
|
|
22
22
|
|
|
23
|
-
def can_encode?
|
|
24
|
-
''.respond_to?(:encoding) && charset
|
|
25
|
-
end
|
|
26
|
-
|
|
27
23
|
def encoded_text
|
|
28
24
|
if 'utf-16'.casecmp(charset) == 0
|
|
29
25
|
encode_utf_16
|
data/lib/httparty/utils.rb
CHANGED
|
@@ -3,11 +3,7 @@
|
|
|
3
3
|
module HTTParty
|
|
4
4
|
module Utils
|
|
5
5
|
def self.stringify_keys(hash)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
hash.each_with_object({}) do |(key, value), new_hash|
|
|
9
|
-
new_hash[key.to_s] = value
|
|
10
|
-
end
|
|
6
|
+
hash.transform_keys(&:to_s)
|
|
11
7
|
end
|
|
12
8
|
end
|
|
13
9
|
end
|
data/lib/httparty/version.rb
CHANGED
data/lib/httparty.rb
CHANGED
|
@@ -28,7 +28,7 @@ module HTTParty
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# == Common Request Options
|
|
31
|
-
# Request methods (get, post, patch, put, delete, head, options) all take a common set of options. These are:
|
|
31
|
+
# Request methods (get, post, patch, put, delete, move, copy, head, options, mkcol, lock, unlock) all take a common set of options. These are:
|
|
32
32
|
#
|
|
33
33
|
# [:+body+:] Body of the request. If passed an object that responds to #to_hash, will try to normalize it first, by default passing it to ActiveSupport::to_params. Any other kind of object will get used as-is.
|
|
34
34
|
# [:+http_proxyaddr+:] Address of proxy server to use.
|
|
@@ -37,7 +37,11 @@ module HTTParty
|
|
|
37
37
|
# [:+http_proxypass+:] Password for proxy server authentication.
|
|
38
38
|
# [:+limit+:] Maximum number of redirects to follow. Takes precedences over :+no_follow+.
|
|
39
39
|
# [:+query+:] Query string, or an object that responds to #to_hash representing it. Normalized according to the same rules as :+body+. If you specify this on a POST, you must use an object which responds to #to_hash. See also HTTParty::ClassMethods.default_params.
|
|
40
|
-
# [:+timeout+:] Timeout for opening connection and
|
|
40
|
+
# [:+timeout+:] Timeout for opening the connection, reading and writing.
|
|
41
|
+
# [:+open_timeout+:] Timeout for opening the connection. Overrides :+timeout+.
|
|
42
|
+
# [:+read_timeout+:] Timeout for each read. Overrides :+timeout+.
|
|
43
|
+
# [:+write_timeout+:] Timeout for each write. Overrides :+timeout+.
|
|
44
|
+
# [:+max_retries+:] Number of times Net::HTTP retries an idempotent request that times out or fails after connecting. Net::HTTP's default is 1.
|
|
41
45
|
# [:+local_host+:] Local address to bind to before connecting.
|
|
42
46
|
# [:+local_port+:] Local port to bind to before connecting.
|
|
43
47
|
# [:+body_stream+:] Allow streaming to a REST server to specify a body_stream.
|
|
@@ -85,11 +89,12 @@ module HTTParty
|
|
|
85
89
|
end
|
|
86
90
|
|
|
87
91
|
# Raises HTTParty::ResponseError if the response status matches a code,
|
|
88
|
-
# range, or regular expression string.
|
|
92
|
+
# range, or regular expression string. Codes and strings match anywhere
|
|
93
|
+
# in the status, so '3..' means any 3xx while '3[0-9]*' also matches 403.
|
|
89
94
|
#
|
|
90
95
|
# class Foo
|
|
91
96
|
# include HTTParty
|
|
92
|
-
# raise_on [404, 500..599, '3
|
|
97
|
+
# raise_on [404, 500..599, '3..']
|
|
93
98
|
# end
|
|
94
99
|
def raise_on(codes = [])
|
|
95
100
|
default_options[:raise_on] = codes.is_a?(Range) ? [codes] : [*codes]
|
|
@@ -210,7 +215,6 @@ module HTTParty
|
|
|
210
215
|
end
|
|
211
216
|
|
|
212
217
|
# Allows setting a default write_timeout for all HTTP calls in seconds
|
|
213
|
-
# Supported by Ruby > 2.6.0
|
|
214
218
|
#
|
|
215
219
|
# class Foo
|
|
216
220
|
# include HTTParty
|
|
@@ -251,7 +255,7 @@ module HTTParty
|
|
|
251
255
|
|
|
252
256
|
def cookies(h = {})
|
|
253
257
|
raise ArgumentError, 'Cookies must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
|
|
254
|
-
default_cookies.add_cookies(h)
|
|
258
|
+
default_cookies.add_cookies(h.to_hash)
|
|
255
259
|
end
|
|
256
260
|
|
|
257
261
|
# Proceed to the location header when an HTTP response dictates a redirect.
|
|
@@ -328,8 +332,9 @@ module HTTParty
|
|
|
328
332
|
# even on redirects that should logically become GET requests.
|
|
329
333
|
# A 303 redirect in HTTP signifies that the redirected url should normally
|
|
330
334
|
# retrieved using a GET request, for instance, it is the output of a previous
|
|
331
|
-
# POST. maintain_method_across_redirects respects this behavior
|
|
332
|
-
# can force HTTParty to resend_on_redirect
|
|
335
|
+
# POST. maintain_method_across_redirects respects this behavior (a HEAD
|
|
336
|
+
# request stays a HEAD), but you can force HTTParty to resend_on_redirect
|
|
337
|
+
# even on 303 responses.
|
|
333
338
|
#
|
|
334
339
|
# @example
|
|
335
340
|
# class Foo
|
|
@@ -396,7 +401,7 @@ module HTTParty
|
|
|
396
401
|
default_options[:query_string_normalizer] = normalizer
|
|
397
402
|
end
|
|
398
403
|
|
|
399
|
-
# Allows setting of SSL version to use.
|
|
404
|
+
# Allows setting of SSL version to use.
|
|
400
405
|
# You can get a list of valid versions from OpenSSL::SSL::SSLContext::METHODS.
|
|
401
406
|
#
|
|
402
407
|
# class Foo
|
|
@@ -423,7 +428,7 @@ module HTTParty
|
|
|
423
428
|
default_options[:skip_decompression] = !!value
|
|
424
429
|
end
|
|
425
430
|
|
|
426
|
-
# Allows setting of SSL ciphers to use.
|
|
431
|
+
# Allows setting of SSL ciphers to use.
|
|
427
432
|
# You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers.
|
|
428
433
|
# You also can specify a cipher suite here, listed here at openssl.org:
|
|
429
434
|
# http://www.openssl.org/docs/apps/ciphers.html#CIPHER_SUITE_NAMES
|
|
@@ -575,8 +580,7 @@ module HTTParty
|
|
|
575
580
|
|
|
576
581
|
# Perform a HEAD request to a path
|
|
577
582
|
def head(path, options = {}, &block)
|
|
578
|
-
|
|
579
|
-
perform_request Net::HTTP::Head, path, options, &block
|
|
583
|
+
perform_request Net::HTTP::Head, path, { maintain_method_across_redirects: true }.merge(options), &block
|
|
580
584
|
end
|
|
581
585
|
|
|
582
586
|
# Perform an OPTIONS request to a path
|
|
@@ -589,10 +593,12 @@ module HTTParty
|
|
|
589
593
|
perform_request Net::HTTP::Mkcol, path, options, &block
|
|
590
594
|
end
|
|
591
595
|
|
|
596
|
+
# Perform a LOCK request to a path
|
|
592
597
|
def lock(path, options = {}, &block)
|
|
593
598
|
perform_request Net::HTTP::Lock, path, options, &block
|
|
594
599
|
end
|
|
595
600
|
|
|
601
|
+
# Perform an UNLOCK request to a path
|
|
596
602
|
def unlock(path, options = {}, &block)
|
|
597
603
|
perform_request Net::HTTP::Unlock, path, options, &block
|
|
598
604
|
end
|
|
@@ -612,12 +618,6 @@ module HTTParty
|
|
|
612
618
|
raise ArgumentError, "#{ timeout_type } must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float))
|
|
613
619
|
end
|
|
614
620
|
|
|
615
|
-
def ensure_method_maintained_across_redirects(options)
|
|
616
|
-
unless options.key?(:maintain_method_across_redirects)
|
|
617
|
-
options[:maintain_method_across_redirects] = true
|
|
618
|
-
end
|
|
619
|
-
end
|
|
620
|
-
|
|
621
621
|
def perform_request(http_method, path, options, &block) #:nodoc:
|
|
622
622
|
build_request(http_method, path, options).perform(&block)
|
|
623
623
|
end
|
|
@@ -687,6 +687,18 @@ module HTTParty
|
|
|
687
687
|
Basement.options(*args, &block)
|
|
688
688
|
end
|
|
689
689
|
|
|
690
|
+
def self.mkcol(*args, &block)
|
|
691
|
+
Basement.mkcol(*args, &block)
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
def self.lock(*args, &block)
|
|
695
|
+
Basement.lock(*args, &block)
|
|
696
|
+
end
|
|
697
|
+
|
|
698
|
+
def self.unlock(*args, &block)
|
|
699
|
+
Basement.unlock(*args, &block)
|
|
700
|
+
end
|
|
701
|
+
|
|
690
702
|
def self.build_request(*args, &block)
|
|
691
703
|
Basement.build_request(*args, &block)
|
|
692
704
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: httparty
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
8
8
|
- Sandro Turriate
|
|
9
|
+
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2026-11-20 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: csv
|
|
@@ -61,28 +62,22 @@ extensions: []
|
|
|
61
62
|
extra_rdoc_files: []
|
|
62
63
|
files:
|
|
63
64
|
- ".editorconfig"
|
|
64
|
-
- ".github/dependabot.yml"
|
|
65
|
-
- ".github/workflows/ci.yml"
|
|
66
65
|
- ".gitignore"
|
|
67
|
-
- ".rubocop.yml"
|
|
68
|
-
- ".rubocop_todo.yml"
|
|
69
66
|
- CONTRIBUTING.md
|
|
70
67
|
- Changelog.md
|
|
71
|
-
- Gemfile
|
|
72
|
-
- Guardfile
|
|
73
68
|
- MIT-LICENSE
|
|
74
69
|
- README.md
|
|
75
70
|
- Rakefile
|
|
76
71
|
- bin/httparty
|
|
77
|
-
- cucumber.yml
|
|
78
72
|
- docs/README.md
|
|
79
73
|
- examples/README.md
|
|
80
|
-
- examples/aaws.rb
|
|
81
74
|
- examples/basic.rb
|
|
75
|
+
- examples/basic_auth.rb
|
|
82
76
|
- examples/body_stream.rb
|
|
77
|
+
- examples/cookies.rb
|
|
83
78
|
- examples/crack.rb
|
|
84
79
|
- examples/custom_parsers.rb
|
|
85
|
-
- examples/
|
|
80
|
+
- examples/debug_output.rb
|
|
86
81
|
- examples/google.rb
|
|
87
82
|
- examples/headers_and_user_agents.rb
|
|
88
83
|
- examples/idn.rb
|
|
@@ -93,11 +88,8 @@ files:
|
|
|
93
88
|
- examples/party_foul_mode.rb
|
|
94
89
|
- examples/peer_cert.rb
|
|
95
90
|
- examples/rescue_json.rb
|
|
96
|
-
- examples/rubyurl.rb
|
|
97
91
|
- examples/stackexchange.rb
|
|
98
92
|
- examples/stream_download.rb
|
|
99
|
-
- examples/tripit_sign_in.rb
|
|
100
|
-
- examples/twitter.rb
|
|
101
93
|
- examples/whoismyrep.rb
|
|
102
94
|
- httparty.gemspec
|
|
103
95
|
- lib/httparty.rb
|
|
@@ -124,9 +116,6 @@ files:
|
|
|
124
116
|
- lib/httparty/text_encoder.rb
|
|
125
117
|
- lib/httparty/utils.rb
|
|
126
118
|
- lib/httparty/version.rb
|
|
127
|
-
- script/release
|
|
128
|
-
- website/css/common.css
|
|
129
|
-
- website/index.html
|
|
130
119
|
homepage: https://github.com/jnunemaker/httparty
|
|
131
120
|
licenses:
|
|
132
121
|
- MIT
|
|
@@ -147,7 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
147
136
|
- !ruby/object:Gem::Version
|
|
148
137
|
version: '0'
|
|
149
138
|
requirements: []
|
|
150
|
-
rubygems_version:
|
|
139
|
+
rubygems_version: 3.3.7
|
|
140
|
+
signing_key:
|
|
151
141
|
specification_version: 4
|
|
152
142
|
summary: Makes http fun! Also, makes consuming restful web services dead easy.
|
|
153
143
|
test_files: []
|
data/.github/dependabot.yml
DELETED
data/.github/workflows/ci.yml
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
on: [push, pull_request]
|
|
3
|
-
jobs:
|
|
4
|
-
build:
|
|
5
|
-
runs-on: ubuntu-latest
|
|
6
|
-
strategy:
|
|
7
|
-
matrix:
|
|
8
|
-
ruby:
|
|
9
|
-
- 2.7
|
|
10
|
-
- "3.0" # Quoted, to avoid YAML float 3.0 interplated to "3"
|
|
11
|
-
- 3.1
|
|
12
|
-
- 3.2
|
|
13
|
-
- 3.3
|
|
14
|
-
- 3.4
|
|
15
|
-
steps:
|
|
16
|
-
- name: Check out repository code
|
|
17
|
-
uses: actions/checkout@v6
|
|
18
|
-
- name: Set up Ruby
|
|
19
|
-
uses: ruby/setup-ruby@v1
|
|
20
|
-
with:
|
|
21
|
-
ruby-version: ${{ matrix.ruby }}
|
|
22
|
-
bundler-cache: true # Run "bundle install", and cache the result automatically.
|
|
23
|
-
- name: Run Rake
|
|
24
|
-
run: bundle exec rake
|