httparty 0.24.2 → 0.24.4
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/README.md +1 -1
- 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 +3 -3
- data/lib/httparty/cookie_hash.rb +1 -1
- data/lib/httparty/headers_processor.rb +4 -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 +38 -6
- data/lib/httparty/request/body.rb +2 -2
- data/lib/httparty/request/streaming_multipart_body.rb +9 -2
- data/lib/httparty/request.rb +29 -6
- data/lib/httparty/response.rb +17 -2
- 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 +16 -16
- metadata +5 -17
- 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
|
|
@@ -103,11 +104,12 @@ module HTTParty
|
|
|
103
104
|
# @return [nil] when the response body is nil, an empty string, spaces only or "null"
|
|
104
105
|
def parse
|
|
105
106
|
return nil if body.nil?
|
|
107
|
+
# The bom has to be removed before the blank body checks below, otherwise a
|
|
108
|
+
# body that is nothing but a bom is handed to the format parser as an
|
|
109
|
+
# empty string and blows up instead of being reported as nil.
|
|
110
|
+
@body = strip_utf8_bom(body)
|
|
106
111
|
return nil if body == 'null'
|
|
107
112
|
return nil if body.valid_encoding? && body.strip.empty?
|
|
108
|
-
if body.valid_encoding? && body.encoding == Encoding::UTF_8
|
|
109
|
-
@body = body.gsub(/\A#{UTF8_BOM}/, '')
|
|
110
|
-
end
|
|
111
113
|
if supports_format?
|
|
112
114
|
parse_supported_format
|
|
113
115
|
else
|
|
@@ -119,14 +121,44 @@ module HTTParty
|
|
|
119
121
|
|
|
120
122
|
def xml
|
|
121
123
|
require 'multi_xml'
|
|
122
|
-
MultiXml.parse(body)
|
|
124
|
+
(defined?(MultiXML) ? MultiXML : MultiXml).parse(body)
|
|
123
125
|
end
|
|
124
126
|
|
|
125
127
|
UTF8_BOM = "\xEF\xBB\xBF"
|
|
128
|
+
UTF8_BOM_ENCODINGS = [Encoding::UTF_8, Encoding::US_ASCII, Encoding::BINARY].freeze
|
|
129
|
+
|
|
130
|
+
# Compares bytes rather than characters because Net::HTTP hands bodies
|
|
131
|
+
# over as ASCII-8BIT when the response has no charset, and a UTF-8 regex
|
|
132
|
+
# would never match those. ASCII-8BIT bodies in a format we don't parse
|
|
133
|
+
# are left alone, since they may be genuine binary data (images, files).
|
|
134
|
+
def strip_utf8_bom(string)
|
|
135
|
+
return string unless UTF8_BOM_ENCODINGS.include?(string.encoding)
|
|
136
|
+
return string if string.encoding == Encoding::BINARY && !supports_format?
|
|
137
|
+
return string.byteslice(UTF8_BOM.bytesize..-1) if utf8_bom?(string)
|
|
138
|
+
|
|
139
|
+
# Valid UTF-8 bodies have always been handed back as a copy, so mutating
|
|
140
|
+
# parsed_response doesn't also change response.body. Other encodings
|
|
141
|
+
# (ASCII-8BIT, US-ASCII, ISO-8859-1, invalid UTF-8) have always been
|
|
142
|
+
# handed back as the same object, and still are.
|
|
143
|
+
if string.encoding == Encoding::UTF_8 && string.valid_encoding?
|
|
144
|
+
string.dup
|
|
145
|
+
else
|
|
146
|
+
string
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Checks bytes one at a time so the common no-BOM case allocates nothing.
|
|
151
|
+
def utf8_bom?(string)
|
|
152
|
+
string.getbyte(0) == 0xEF && string.getbyte(1) == 0xBB && string.getbyte(2) == 0xBF
|
|
153
|
+
end
|
|
126
154
|
|
|
127
155
|
def json
|
|
128
156
|
require 'json'
|
|
129
|
-
JSON.
|
|
157
|
+
if JSON::VERSION.to_i >= 3
|
|
158
|
+
JSON.parse(body, :allow_nan => true)
|
|
159
|
+
else
|
|
160
|
+
JSON.parse(body, :quirks_mode => true, :allow_nan => true)
|
|
161
|
+
end
|
|
130
162
|
end
|
|
131
163
|
|
|
132
164
|
def csv
|
|
@@ -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
|
|
@@ -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
|
@@ -78,11 +78,15 @@ module HTTParty
|
|
|
78
78
|
|
|
79
79
|
def path=(uri)
|
|
80
80
|
uri_adapter = options[:uri_adapter]
|
|
81
|
+
@slash_added_to_empty_path = false
|
|
81
82
|
|
|
82
83
|
@path = if uri.is_a?(uri_adapter)
|
|
83
84
|
uri
|
|
84
85
|
elsif String.try_convert(uri)
|
|
85
|
-
uri_adapter.parse(uri)
|
|
86
|
+
parsed_uri = uri_adapter.parse(uri)
|
|
87
|
+
normalized_uri = parsed_uri.normalize
|
|
88
|
+
@slash_added_to_empty_path = empty_path_reference?(parsed_uri) && normalized_uri.path == '/'
|
|
89
|
+
normalized_uri
|
|
86
90
|
else
|
|
87
91
|
raise ArgumentError,
|
|
88
92
|
"bad argument (expected #{uri_adapter} object or URI string)"
|
|
@@ -93,7 +97,7 @@ module HTTParty
|
|
|
93
97
|
if uri.respond_to? :request_uri
|
|
94
98
|
uri.request_uri
|
|
95
99
|
else
|
|
96
|
-
uri.path
|
|
100
|
+
uri.query ? "#{uri.path}?#{uri.query}" : uri.path
|
|
97
101
|
end
|
|
98
102
|
end
|
|
99
103
|
|
|
@@ -109,6 +113,7 @@ module HTTParty
|
|
|
109
113
|
new_uri = options[:uri_adapter].parse("#{@last_uri.scheme}:#{path}").normalize
|
|
110
114
|
elsif path.relative?
|
|
111
115
|
new_uri = options[:uri_adapter].parse("#{base_uri}#{path}").normalize
|
|
116
|
+
warn_about_empty_path_trailing_slash(new_uri) if !redirect && @slash_added_to_empty_path && new_uri.path != '/'
|
|
112
117
|
else
|
|
113
118
|
new_uri = path.clone
|
|
114
119
|
end
|
|
@@ -171,7 +176,7 @@ module HTTParty
|
|
|
171
176
|
end
|
|
172
177
|
|
|
173
178
|
handle_host_redirection if response_redirects?
|
|
174
|
-
result = handle_unauthorized
|
|
179
|
+
result = handle_unauthorized(&block)
|
|
175
180
|
result ||= handle_response(chunked_body, &block)
|
|
176
181
|
result
|
|
177
182
|
rescue *COMMON_NETWORK_ERRORS => e
|
|
@@ -191,9 +196,7 @@ module HTTParty
|
|
|
191
196
|
end
|
|
192
197
|
|
|
193
198
|
def _dump(_level)
|
|
194
|
-
opts = options.
|
|
195
|
-
opts.delete(:logger)
|
|
196
|
-
opts.delete(:parser) if opts[:parser] && opts[:parser].is_a?(Proc)
|
|
199
|
+
opts = options.reject { |key, value| value.is_a?(Proc) || %i[logger debug_output].include?(key) }
|
|
197
200
|
Marshal.dump([http_method, path, opts, last_response, @last_uri, @raw_request])
|
|
198
201
|
end
|
|
199
202
|
|
|
@@ -445,6 +448,26 @@ module HTTParty
|
|
|
445
448
|
).call
|
|
446
449
|
end
|
|
447
450
|
|
|
451
|
+
# A reference with no scheme, host or path ("", "?query" or "#fragment")
|
|
452
|
+
# refers to the base URI itself (RFC 3986 section 5.2.2).
|
|
453
|
+
def empty_path_reference?(uri)
|
|
454
|
+
uri.scheme.nil? && uri.host.nil? && uri.path.to_s.empty?
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
def warn_about_empty_path_trailing_slash(new_uri)
|
|
458
|
+
@slash_added_to_empty_path = false # warn once per request
|
|
459
|
+
trace_line = caller.reject { |line| line.include?('httparty') }.first
|
|
460
|
+
warning = "[DEPRECATION] HTTParty added a trailing slash to the request path " \
|
|
461
|
+
"(#{new_uri.path}) because the path passed to the request was empty. " \
|
|
462
|
+
"In HTTParty 0.25, an empty, query-only (\"?a=1\") or fragment-only path " \
|
|
463
|
+
"will request the base_uri path as-is, without a trailing slash, matching " \
|
|
464
|
+
"RFC 3986 and other HTTP clients. To keep the trailing slash, pass \"/\" as the path. " \
|
|
465
|
+
"For more info refer to: https://github.com/jnunemaker/httparty/issues/742\n" \
|
|
466
|
+
"#{trace_line}"
|
|
467
|
+
|
|
468
|
+
warn(warning)
|
|
469
|
+
end
|
|
470
|
+
|
|
448
471
|
def validate_uri_safety!(new_uri)
|
|
449
472
|
return if options[:skip_uri_validation]
|
|
450
473
|
|
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
|
|
@@ -133,13 +134,27 @@ module HTTParty
|
|
|
133
134
|
end
|
|
134
135
|
|
|
135
136
|
def throw_exception
|
|
136
|
-
|
|
137
|
+
raise_on = @request.options[:raise_on]
|
|
138
|
+
return if raise_on.nil?
|
|
139
|
+
|
|
140
|
+
matchers = raise_on.is_a?(Range) ? [raise_on] : [*raise_on]
|
|
141
|
+
|
|
142
|
+
if matchers.any? { |matcher| code_matches?(matcher) }
|
|
137
143
|
::Kernel.raise ::HTTParty::ResponseError.new(@response), "Code #{code} - #{body}"
|
|
138
144
|
end
|
|
139
145
|
end
|
|
140
146
|
|
|
141
147
|
private
|
|
142
148
|
|
|
149
|
+
def code_matches?(matcher)
|
|
150
|
+
case matcher
|
|
151
|
+
when Range
|
|
152
|
+
matcher.cover?(code) || matcher.cover?(code.to_s)
|
|
153
|
+
else
|
|
154
|
+
/#{matcher}/.match?(code.to_s)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
143
158
|
def warn_about_nil_deprecation
|
|
144
159
|
trace_line = caller.reject { |line| line.include?('httparty') }.first
|
|
145
160
|
warning = "[DEPRECATION] HTTParty will no longer override `response#nil?`. " \
|
|
@@ -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
|
@@ -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.
|
|
@@ -84,14 +88,16 @@ module HTTParty
|
|
|
84
88
|
default_options[:log_format] = format
|
|
85
89
|
end
|
|
86
90
|
|
|
87
|
-
# Raises HTTParty::ResponseError if response
|
|
91
|
+
# Raises HTTParty::ResponseError if the response status matches a code,
|
|
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.
|
|
88
94
|
#
|
|
89
95
|
# class Foo
|
|
90
96
|
# include HTTParty
|
|
91
|
-
# raise_on [404, 500, '
|
|
97
|
+
# raise_on [404, 500..599, '3..']
|
|
92
98
|
# end
|
|
93
99
|
def raise_on(codes = [])
|
|
94
|
-
default_options[:raise_on] = *codes
|
|
100
|
+
default_options[:raise_on] = codes.is_a?(Range) ? [codes] : [*codes]
|
|
95
101
|
end
|
|
96
102
|
|
|
97
103
|
# Allows setting http proxy information to be used
|
|
@@ -209,7 +215,6 @@ module HTTParty
|
|
|
209
215
|
end
|
|
210
216
|
|
|
211
217
|
# Allows setting a default write_timeout for all HTTP calls in seconds
|
|
212
|
-
# Supported by Ruby > 2.6.0
|
|
213
218
|
#
|
|
214
219
|
# class Foo
|
|
215
220
|
# include HTTParty
|
|
@@ -250,7 +255,7 @@ module HTTParty
|
|
|
250
255
|
|
|
251
256
|
def cookies(h = {})
|
|
252
257
|
raise ArgumentError, 'Cookies must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
|
|
253
|
-
default_cookies.add_cookies(h)
|
|
258
|
+
default_cookies.add_cookies(h.to_hash)
|
|
254
259
|
end
|
|
255
260
|
|
|
256
261
|
# Proceed to the location header when an HTTP response dictates a redirect.
|
|
@@ -395,7 +400,7 @@ module HTTParty
|
|
|
395
400
|
default_options[:query_string_normalizer] = normalizer
|
|
396
401
|
end
|
|
397
402
|
|
|
398
|
-
# Allows setting of SSL version to use.
|
|
403
|
+
# Allows setting of SSL version to use.
|
|
399
404
|
# You can get a list of valid versions from OpenSSL::SSL::SSLContext::METHODS.
|
|
400
405
|
#
|
|
401
406
|
# class Foo
|
|
@@ -422,7 +427,7 @@ module HTTParty
|
|
|
422
427
|
default_options[:skip_decompression] = !!value
|
|
423
428
|
end
|
|
424
429
|
|
|
425
|
-
# Allows setting of SSL ciphers to use.
|
|
430
|
+
# Allows setting of SSL ciphers to use.
|
|
426
431
|
# You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers.
|
|
427
432
|
# You also can specify a cipher suite here, listed here at openssl.org:
|
|
428
433
|
# http://www.openssl.org/docs/apps/ciphers.html#CIPHER_SUITE_NAMES
|
|
@@ -574,8 +579,7 @@ module HTTParty
|
|
|
574
579
|
|
|
575
580
|
# Perform a HEAD request to a path
|
|
576
581
|
def head(path, options = {}, &block)
|
|
577
|
-
|
|
578
|
-
perform_request Net::HTTP::Head, path, options, &block
|
|
582
|
+
perform_request Net::HTTP::Head, path, { maintain_method_across_redirects: true }.merge(options), &block
|
|
579
583
|
end
|
|
580
584
|
|
|
581
585
|
# Perform an OPTIONS request to a path
|
|
@@ -588,10 +592,12 @@ module HTTParty
|
|
|
588
592
|
perform_request Net::HTTP::Mkcol, path, options, &block
|
|
589
593
|
end
|
|
590
594
|
|
|
595
|
+
# Perform a LOCK request to a path
|
|
591
596
|
def lock(path, options = {}, &block)
|
|
592
597
|
perform_request Net::HTTP::Lock, path, options, &block
|
|
593
598
|
end
|
|
594
599
|
|
|
600
|
+
# Perform an UNLOCK request to a path
|
|
595
601
|
def unlock(path, options = {}, &block)
|
|
596
602
|
perform_request Net::HTTP::Unlock, path, options, &block
|
|
597
603
|
end
|
|
@@ -611,12 +617,6 @@ module HTTParty
|
|
|
611
617
|
raise ArgumentError, "#{ timeout_type } must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float))
|
|
612
618
|
end
|
|
613
619
|
|
|
614
|
-
def ensure_method_maintained_across_redirects(options)
|
|
615
|
-
unless options.key?(:maintain_method_across_redirects)
|
|
616
|
-
options[:maintain_method_across_redirects] = true
|
|
617
|
-
end
|
|
618
|
-
end
|
|
619
|
-
|
|
620
620
|
def perform_request(http_method, path, options, &block) #:nodoc:
|
|
621
621
|
build_request(http_method, path, options).perform(&block)
|
|
622
622
|
end
|
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.24.
|
|
4
|
+
version: 0.24.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-
|
|
12
|
+
date: 2026-11-20 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: csv
|
|
@@ -62,28 +62,22 @@ extensions: []
|
|
|
62
62
|
extra_rdoc_files: []
|
|
63
63
|
files:
|
|
64
64
|
- ".editorconfig"
|
|
65
|
-
- ".github/dependabot.yml"
|
|
66
|
-
- ".github/workflows/ci.yml"
|
|
67
65
|
- ".gitignore"
|
|
68
|
-
- ".rubocop.yml"
|
|
69
|
-
- ".rubocop_todo.yml"
|
|
70
66
|
- CONTRIBUTING.md
|
|
71
67
|
- Changelog.md
|
|
72
|
-
- Gemfile
|
|
73
|
-
- Guardfile
|
|
74
68
|
- MIT-LICENSE
|
|
75
69
|
- README.md
|
|
76
70
|
- Rakefile
|
|
77
71
|
- bin/httparty
|
|
78
|
-
- cucumber.yml
|
|
79
72
|
- docs/README.md
|
|
80
73
|
- examples/README.md
|
|
81
|
-
- examples/aaws.rb
|
|
82
74
|
- examples/basic.rb
|
|
75
|
+
- examples/basic_auth.rb
|
|
83
76
|
- examples/body_stream.rb
|
|
77
|
+
- examples/cookies.rb
|
|
84
78
|
- examples/crack.rb
|
|
85
79
|
- examples/custom_parsers.rb
|
|
86
|
-
- examples/
|
|
80
|
+
- examples/debug_output.rb
|
|
87
81
|
- examples/google.rb
|
|
88
82
|
- examples/headers_and_user_agents.rb
|
|
89
83
|
- examples/idn.rb
|
|
@@ -94,11 +88,8 @@ files:
|
|
|
94
88
|
- examples/party_foul_mode.rb
|
|
95
89
|
- examples/peer_cert.rb
|
|
96
90
|
- examples/rescue_json.rb
|
|
97
|
-
- examples/rubyurl.rb
|
|
98
91
|
- examples/stackexchange.rb
|
|
99
92
|
- examples/stream_download.rb
|
|
100
|
-
- examples/tripit_sign_in.rb
|
|
101
|
-
- examples/twitter.rb
|
|
102
93
|
- examples/whoismyrep.rb
|
|
103
94
|
- httparty.gemspec
|
|
104
95
|
- lib/httparty.rb
|
|
@@ -125,9 +116,6 @@ files:
|
|
|
125
116
|
- lib/httparty/text_encoder.rb
|
|
126
117
|
- lib/httparty/utils.rb
|
|
127
118
|
- lib/httparty/version.rb
|
|
128
|
-
- script/release
|
|
129
|
-
- website/css/common.css
|
|
130
|
-
- website/index.html
|
|
131
119
|
homepage: https://github.com/jnunemaker/httparty
|
|
132
120
|
licenses:
|
|
133
121
|
- MIT
|
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@v4
|
|
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
|
data/.rubocop.yml
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
inherit_from: .rubocop_todo.yml
|
|
2
|
-
|
|
3
|
-
# Offense count: 963
|
|
4
|
-
# Cop supports --auto-correct.
|
|
5
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
6
|
-
Style/StringLiterals:
|
|
7
|
-
Enabled: false
|
|
8
|
-
|
|
9
|
-
# Offense count: 327
|
|
10
|
-
# Cop supports --auto-correct.
|
|
11
|
-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
|
12
|
-
Style/SpaceInsideHashLiteralBraces:
|
|
13
|
-
Enabled: false
|
|
14
|
-
|
|
15
|
-
# Offense count: 33
|
|
16
|
-
# Cop supports --auto-correct.
|
|
17
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
|
18
|
-
Style/SpaceInsideBlockBraces:
|
|
19
|
-
Enabled: false
|
|
20
|
-
|
|
21
|
-
# Offense count: 1
|
|
22
|
-
# Cop supports --auto-correct.
|
|
23
|
-
Style/SpaceBeforeSemicolon:
|
|
24
|
-
Enabled: false
|
|
25
|
-
|
|
26
|
-
# Offense count: 20
|
|
27
|
-
# Cop supports --auto-correct.
|
|
28
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
29
|
-
Style/SignalException:
|
|
30
|
-
Enabled: false
|
|
31
|
-
|
|
32
|
-
# Offense count: 1
|
|
33
|
-
# Configuration parameters: Methods.
|
|
34
|
-
Style/SingleLineBlockParams:
|
|
35
|
-
Enabled: false
|
|
36
|
-
|
|
37
|
-
# Offense count: 6
|
|
38
|
-
# Cop supports --auto-correct.
|
|
39
|
-
Style/PerlBackrefs:
|
|
40
|
-
Enabled: false
|
|
41
|
-
|
|
42
|
-
# Offense count: 2
|
|
43
|
-
# Cop supports --auto-correct.
|
|
44
|
-
# Configuration parameters: AllowAsExpressionSeparator.
|
|
45
|
-
Style/Semicolon:
|
|
46
|
-
Enabled: false
|
|
47
|
-
|
|
48
|
-
# Offense count: 77
|
|
49
|
-
# Cop supports --auto-correct.
|
|
50
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
51
|
-
Style/BracesAroundHashParameters:
|
|
52
|
-
Enabled: false
|
|
53
|
-
|
|
54
|
-
# Offense count: 36
|
|
55
|
-
Style/Documentation:
|
|
56
|
-
Enabled: false
|
|
57
|
-
|
|
58
|
-
# Offense count: 6
|
|
59
|
-
# Cop supports --auto-correct.
|
|
60
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
|
61
|
-
Style/RegexpLiteral:
|
|
62
|
-
Enabled: false
|
|
63
|
-
|
|
64
|
-
# Offense count: 5
|
|
65
|
-
# Cop supports --auto-correct.
|
|
66
|
-
Style/NumericLiterals:
|
|
67
|
-
MinDigits: 6
|
|
68
|
-
|
|
69
|
-
# Offense count: 4
|
|
70
|
-
# Cop supports --auto-correct.
|
|
71
|
-
Lint/UnusedMethodArgument:
|
|
72
|
-
Enabled: false
|
|
73
|
-
|
|
74
|
-
# Offense count: 11
|
|
75
|
-
# Cop supports --auto-correct.
|
|
76
|
-
Lint/UnusedBlockArgument:
|
|
77
|
-
Enabled: false
|
|
78
|
-
|
|
79
|
-
# Offense count: 1
|
|
80
|
-
Lint/Void:
|
|
81
|
-
Enabled: false
|
|
82
|
-
|
|
83
|
-
# Offense count: 22
|
|
84
|
-
# Cop supports --auto-correct.
|
|
85
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
86
|
-
Style/IndentHash:
|
|
87
|
-
Enabled: false
|
|
88
|
-
|
|
89
|
-
# Offense count: 7
|
|
90
|
-
# Configuration parameters: MinBodyLength.
|
|
91
|
-
Style/GuardClause:
|
|
92
|
-
Enabled: false
|