httparty 0.24.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dd88885a49c925e66a28cb979491ade60280598f97c1051a07624e5cbbf7ce5
4
- data.tar.gz: 3ab8ceca964d91507981c5508f994105030727ed2c347262ae8aa353481432ce
3
+ metadata.gz: f086f07dd66b6d801b3a103e90f2c53d42549081324c495e840a118dd6227e49
4
+ data.tar.gz: 460a21e7486089bad58092ac13db538b0b6eabd019ecab8c1f4e5272ba0e700a
5
5
  SHA512:
6
- metadata.gz: b29fc69f69247a3621ada6b919c9d420892d5ecc4c1ca474bf78a59f9c324a7e772c85d4f5374f973dc606a76033e5ad741cfc67decf8b8561459f974095b2ef
7
- data.tar.gz: 7fbb9fefc822c17e33d85bd6452a0a17a90dc5a0781abea2df753a812ff80fd2106425c29ed0b3fe2d85d2fb32d89b48b7976f553952bc4c74b570fdebc79990
6
+ metadata.gz: 80f68016d35bab11bb2c218021463a7bd3c6224e6e11fbc2ad703b6f32801f992da79497607a162863b7d0fd25717a88eb25b0248afb673330a72b187b1633f0
7
+ data.tar.gz: a7422e258662e81f4869a21f7c235db0216dbdc41e93ac719bbc512296f46951517be887d8aec84f077dd308bbc46a5262f4341f5dbfe390f64c5f401287768e
@@ -17,7 +17,7 @@ module HTTParty
17
17
  # def connection
18
18
  # puts uri
19
19
  # puts options
20
- # Net::HTTP.new(uri)
20
+ # super
21
21
  # end
22
22
  # end
23
23
  #
@@ -25,12 +25,12 @@ module HTTParty
25
25
  # class CountingConnectionAdapter < HTTParty::ConnectionAdapter
26
26
  # @@count = 0
27
27
  #
28
- # self.count
28
+ # def self.count
29
29
  # @@count
30
30
  # end
31
31
  #
32
32
  # def connection
33
- # self.count += 1
33
+ # @@count += 1
34
34
  # super
35
35
  # end
36
36
  # end
@@ -11,6 +11,7 @@ module HTTParty
11
11
 
12
12
  def call
13
13
  return unless options[:headers]
14
+ raise ArgumentError, ':headers must be a hash' unless options[:headers].respond_to?(:to_hash)
14
15
 
15
16
  options[:headers] = headers.merge(options[:headers]) if headers.any?
16
17
  options[:headers] = Utils.stringify_keys(process_dynamic_headers)
@@ -91,7 +91,9 @@ module HTTParty
91
91
 
92
92
  def normalize_query(query)
93
93
  if query_string_normalizer
94
- query_string_normalizer.call(query)
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
@@ -78,15 +78,18 @@ module HTTParty
78
78
 
79
79
  def path=(uri)
80
80
  uri_adapter = options[:uri_adapter]
81
- @slash_added_to_empty_path = false
82
81
 
83
82
  @path = if uri.is_a?(uri_adapter)
84
83
  uri
85
- elsif String.try_convert(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
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
90
93
  else
91
94
  raise ArgumentError,
92
95
  "bad argument (expected #{uri_adapter} object or URI string)"
@@ -102,18 +105,18 @@ module HTTParty
102
105
  end
103
106
 
104
107
  def uri
105
- if redirect && path.relative? && path.path[0] != '/'
106
- last_uri_host = @last_uri.path.gsub(/[^\/]+$/, '')
107
-
108
- path.path = "/#{path.path}" if last_uri_host[-1] != '/'
109
- path.path = "#{last_uri_host}#{path.path}"
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))
110
114
  end
111
115
 
112
116
  if path.relative? && path.host
113
117
  new_uri = options[:uri_adapter].parse("#{@last_uri.scheme}:#{path}").normalize
114
118
  elsif path.relative?
115
119
  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 != '/'
117
120
  else
118
121
  new_uri = path.clone
119
122
  end
@@ -338,10 +341,14 @@ module HTTParty
338
341
  logger = HTTParty::Logger.build(options[:logger], options[:log_level], options[:log_format])
339
342
  logger.format(self, last_response)
340
343
  end
341
- self.path = last_response['location']
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
342
348
  self.redirect = true
343
349
  if last_response.class == Net::HTTPSeeOther
344
- unless options[:maintain_method_across_redirects] && options[:resend_on_redirect]
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)
345
352
  self.http_method = Net::HTTP::Get
346
353
  end
347
354
  elsif last_response.code != '307' && last_response.code != '308'
@@ -416,7 +423,7 @@ module HTTParty
416
423
 
417
424
  def validate
418
425
  raise HTTParty::RedirectionTooDeep.new(last_response), 'HTTP redirects too deep' if options[:limit].to_i <= 0
419
- raise ArgumentError, 'only get, post, patch, put, delete, head, and options methods are supported' unless SupportedHTTPMethods.include?(http_method)
426
+ raise ArgumentError, "only #{SupportedHTTPMethods.map { |m| m::METHOD.downcase }.join(', ')} methods are supported" unless SupportedHTTPMethods.include?(http_method)
420
427
  raise ArgumentError, ':headers must be a hash' if options[:headers] && !options[:headers].respond_to?(:to_hash)
421
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]
422
429
  raise ArgumentError, ':basic_auth must be a hash' if options[:basic_auth] && !options[:basic_auth].respond_to?(:to_hash)
@@ -454,20 +461,6 @@ module HTTParty
454
461
  uri.scheme.nil? && uri.host.nil? && uri.path.to_s.empty?
455
462
  end
456
463
 
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
-
471
464
  def validate_uri_safety!(new_uri)
472
465
  return if options[:skip_uri_validation]
473
466
 
@@ -53,7 +53,7 @@ module HTTParty
53
53
 
54
54
  def inspect
55
55
  inspect_id = ::Kernel::format '%x', (object_id * 2)
56
- %(#<#{self.class}:0x#{inspect_id} parsed_response=#{parsed_response.inspect}, @response=#{response.inspect}, @headers=#{headers.inspect}>)
56
+ %(#<#{self.class}:0x#{inspect_id} #{inspect_parsed_response}, @response=#{response.inspect}, @headers=#{headers.inspect}>)
57
57
  end
58
58
 
59
59
  CODES_TO_OBJ = ::Net::HTTPResponse::CODE_CLASS_TO_OBJ.merge ::Net::HTTPResponse::CODE_TO_OBJ
@@ -95,8 +95,12 @@ module HTTParty
95
95
  end
96
96
 
97
97
  def pretty_print(pp)
98
- if !parsed_response.nil? && parsed_response.respond_to?(:pretty_print)
99
- parsed_response.pretty_print(pp)
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)
100
104
  else
101
105
  super
102
106
  end
@@ -146,6 +150,13 @@ module HTTParty
146
150
 
147
151
  private
148
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
+
149
160
  def code_matches?(matcher)
150
161
  case matcher
151
162
  when Range
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTParty
4
- VERSION = '0.24.4'
4
+ VERSION = '0.25.0'
5
5
  end
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.
@@ -332,8 +332,9 @@ module HTTParty
332
332
  # even on redirects that should logically become GET requests.
333
333
  # A 303 redirect in HTTP signifies that the redirected url should normally
334
334
  # retrieved using a GET request, for instance, it is the output of a previous
335
- # POST. maintain_method_across_redirects respects this behavior, but you
336
- # can force HTTParty to resend_on_redirect even on 303 responses.
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.
337
338
  #
338
339
  # @example
339
340
  # class Foo
@@ -686,6 +687,18 @@ module HTTParty
686
687
  Basement.options(*args, &block)
687
688
  end
688
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
+
689
702
  def self.build_request(*args, &block)
690
703
  Basement.build_request(*args, &block)
691
704
  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
4
+ version: 0.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker