httparty 0.19.0 → 0.21.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: 11f43b51a670445d42c8eef37875fa9b2c4340edd67bff72cd1ba6b3dd7a0001
4
- data.tar.gz: b3a0a431cc81a2efde61d232468839001661ef07837a5a91471bc1123601d212
3
+ metadata.gz: 9dccd9b1a1fa3f98ca96da312ccdf19371418815a556b1443acac322a8ae4e15
4
+ data.tar.gz: 61f75235d1dcf4e1e38cbab62869aeeff28de9d0dc27fad30c7ca11d6355cd0d
5
5
  SHA512:
6
- metadata.gz: 8621cfbba4e743544cfdf603a44bd347b4854a099eac6db284b7594151dbf68bf62b393ff445f67fbe4723e4156bb8e0e7760d72b4971a777968c8cdd3fd78e6
7
- data.tar.gz: 1f6f0ea5181a674b91cce360b9d9c3dab1b8a97affc78827aa1d07520066d4712ac93fad73583e439a876ddc80a75b20135c6656d396e3f394d5b3baf04eb127
6
+ metadata.gz: e47fce0ce8b6c4fe97ee0335b4f0544bc039755f12f0c2aac9f47e901739fd172390a3dc01f070d6799b1af335293b5d09a66514deb0810dfafc37f25d2f3c81
7
+ data.tar.gz: 9aa37800410a58a60ca751de44eed1026514b26c408a1f890b48a8f0049c814052a70a55343d3798c3d4d59ca9b157257c1fa83240200d283ba374a9b62db2ef
@@ -5,24 +5,22 @@ jobs:
5
5
  runs-on: ubuntu-latest
6
6
  strategy:
7
7
  matrix:
8
- ruby: ['2.5', '2.6', '2.7']
8
+ ruby:
9
+ - 2.3
10
+ - 2.4
11
+ - 2.5
12
+ - 2.6
13
+ - 2.7
14
+ - '3.0' # Quoted, to avoid YAML float 3.0 interplated to "3"
15
+ - 3.1
16
+ - 3.2
9
17
  steps:
10
18
  - name: Check out repository code
11
- uses: actions/checkout@v2
12
- - name: Do some action caching
13
- uses: actions/cache@v1
14
- with:
15
- path: vendor/bundle
16
- key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
17
- restore-keys: |
18
- ${{ runner.os }}-gem-
19
+ uses: actions/checkout@v3
19
20
  - name: Set up Ruby
20
- uses: actions/setup-ruby@v1
21
+ uses: ruby/setup-ruby@v1
21
22
  with:
22
23
  ruby-version: ${{ matrix.ruby }}
23
- - name: Install bundler
24
- run: gem install bundler
25
- - name: Run bundler
26
- run: bundle install --jobs 4 --retry 3
24
+ bundler-cache: true # Run "bundle install", and cache the result automatically.
27
25
  - name: Run Rake
28
26
  run: bundle exec rake
data/.gitignore CHANGED
@@ -10,4 +10,5 @@ pkg/
10
10
  .rvmrc
11
11
  coverage
12
12
  *.gem
13
- .idea
13
+ .idea
14
+ .tool-versions
data/Changelog.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## 0.21.0
2
+
3
+ * [escape filename in the multipart/form-data Content-Disposition header](https://github.com/jnunemaker/httparty/commit/cdb45a678c43e44570b4e73f84b1abeb5ec22b8e)
4
+ * [Fix request marshaling](https://github.com/jnunemaker/httparty/pull/767)
5
+ * [Replace `mime-types` with `mini_mime`](https://github.com/jnunemaker/httparty/pull/769)
6
+
7
+ ## 0.20.0
8
+
9
+ Breaking changes
10
+
11
+ * Require Ruby >= 2.3.0
12
+
13
+ Fixes
14
+
15
+ * [`Marshal.dump` fails on response objects when request option `:logger` is set or `:parser` is a proc](https://github.com/jnunemaker/httparty/pull/714)
16
+ * [Switch `:pem` option to to `OpenSSL::PKey.read` to support other algorithms](https://github.com/jnunemaker/httparty/pull/720)
17
+
18
+ ## 0.19.1
19
+
20
+ * [Remove use of unary + method for creating non-frozen string to increase compatibility with older versions of ruby](https://github.com/jnunemaker/httparty/commit/4416141d37fd71bdba4f37589ec265f55aa446ce)
21
+
1
22
  ## 0.19.0
2
23
 
3
24
  * [Multipart/Form-Data: rewind files after read](https://github.com/jnunemaker/httparty/pull/709)
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
  gem 'mongrel', '1.2.0.pre2'
6
+ gem 'json'
6
7
 
7
8
  group :development do
8
9
  gem 'guard'
@@ -11,6 +12,7 @@ group :development do
11
12
  end
12
13
 
13
14
  group :test do
15
+ gem 'rexml'
14
16
  gem 'rspec', '~> 3.4'
15
17
  gem 'simplecov', require: false
16
18
  gem 'aruba'
data/Guardfile CHANGED
@@ -1,7 +1,8 @@
1
1
  rspec_options = {
2
- version: 1,
3
2
  all_after_pass: false,
4
- all_on_start: false
3
+ all_on_start: false,
4
+ failed_mode: :keep,
5
+ cmd: 'bundle exec rspec',
5
6
  }
6
7
 
7
8
  guard 'rspec', rspec_options do
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # httparty
2
2
 
3
- [![Build Status](https://travis-ci.org/jnunemaker/httparty.svg?branch=master)](https://travis-ci.org/jnunemaker/httparty)
3
+ [![CI](https://github.com/jnunemaker/httparty/actions/workflows/ci.yml/badge.svg)](https://github.com/jnunemaker/httparty/actions/workflows/ci.yml)
4
4
 
5
5
  Makes http fun again! Ain't no party like a httparty, because a httparty don't stop.
6
6
 
@@ -12,7 +12,7 @@ gem install httparty
12
12
 
13
13
  ## Requirements
14
14
 
15
- * Ruby 2.0.0 or higher
15
+ * Ruby 2.3.0 or higher
16
16
  * multi_xml
17
17
  * You like to party!
18
18
 
data/docs/README.md CHANGED
@@ -14,6 +14,20 @@ response = HTTParty.get('http://example.com', format: :plain)
14
14
  JSON.parse response, symbolize_names: true
15
15
  ```
16
16
 
17
+ ## Posting JSON
18
+ When using Content Type `application/json` with `POST`, `PUT` or `PATCH` requests, the body should be a string of valid JSON:
19
+
20
+ ```ruby
21
+ # With written JSON
22
+ HTTParty.post('http://example.com', body: "{\"foo\":\"bar\"}", headers: { 'Content-Type' => 'application/json' })
23
+
24
+ # Using JSON.generate
25
+ HTTParty.post('http://example.com', body: JSON.generate({ foo: 'bar' }), headers: { 'Content-Type' => 'application/json' })
26
+
27
+ # Using object.to_json
28
+ HTTParty.post('http://example.com', body: { foo: 'bar' }.to_json, headers: { 'Content-Type' => 'application/json' })
29
+ ```
30
+
17
31
  ## Working with SSL
18
32
 
19
33
  You can use this guide to work with SSL certificates.
@@ -123,11 +137,16 @@ If you explicitly set `Accept-Encoding`, there be dragons:
123
137
  `Net::HTTP` will automatically decompress it, and will omit `Content-Encoding`
124
138
  from your `HTTParty::Response` headers.
125
139
 
126
- * For encodings `br` (Brotli) or `compress` (LZW), HTTParty will automatically
127
- decompress if you include the `brotli` or `ruby-lzws` gems respectively into your project.
140
+ * For the following encodings, HTTParty will automatically decompress them if you include
141
+ the required gem into your project. Similar to above, if decompression succeeds,
142
+ `Content-Encoding` will be omitted from your `HTTParty::Response` headers.
128
143
  **Warning:** Support for these encodings is experimental and not fully battle-tested.
129
- Similar to above, if decompression succeeds, `Content-Encoding` will be omitted
130
- from your `HTTParty::Response` headers.
144
+
145
+ | Content-Encoding | Required Gem |
146
+ | --- | --- |
147
+ | `br` (Brotli) | [brotli](https://rubygems.org/gems/brotli) |
148
+ | `compress` (LZW) | [ruby-lzws](https://rubygems.org/gems/ruby-lzws) |
149
+ | `zstd` (Zstandard) | [zstd-ruby](https://rubygems.org/gems/zstd-ruby) |
131
150
 
132
151
  * For other encodings, `HTTParty::Response#body` will return the raw uncompressed byte string,
133
152
  and you'll need to inspect the `Content-Encoding` response header and decompress it yourself.
@@ -147,7 +166,8 @@ JSON.parse(res.body) # safe
147
166
 
148
167
  require 'brotli'
149
168
  require 'lzws'
150
- res = HTTParty.get('https://example.com/test.json', headers: { 'Accept-Encoding' => 'br,compress' })
169
+ require 'zstd-ruby'
170
+ res = HTTParty.get('https://example.com/test.json', headers: { 'Accept-Encoding' => 'br,compress,zstd' })
151
171
  JSON.parse(res.body)
152
172
 
153
173
 
data/httparty.gemspec CHANGED
@@ -13,10 +13,10 @@ 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.0.0'
16
+ s.required_ruby_version = '>= 2.3.0'
17
17
 
18
18
  s.add_dependency 'multi_xml', ">= 0.5.2"
19
- s.add_dependency('mime-types', "~> 3.0")
19
+ s.add_dependency 'mini_mime', ">= 1.0.0"
20
20
 
21
21
  # If this line is removed, all hard partying will cease.
22
22
  s.post_install_message = "When you HTTParty, you must party hard!"
@@ -223,7 +223,7 @@ module HTTParty
223
223
  # Note: options[:pem] must contain the content of a PEM file having the private key appended
224
224
  if options[:pem]
225
225
  http.cert = OpenSSL::X509::Certificate.new(options[:pem])
226
- http.key = OpenSSL::PKey::RSA.new(options[:pem], options[:pem_password])
226
+ http.key = OpenSSL::PKey.read(options[:pem], options[:pem_password])
227
227
  http.verify_mode = verify_ssl_certificate? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
228
228
  end
229
229
 
@@ -17,7 +17,8 @@ module HTTParty
17
17
  'none' => :none,
18
18
  'identity' => :none,
19
19
  'br' => :brotli,
20
- 'compress' => :lzw
20
+ 'compress' => :lzw,
21
+ 'zstd' => :zstd
21
22
  }.freeze
22
23
 
23
24
  # The response body of the request
@@ -88,5 +89,14 @@ module HTTParty
88
89
  nil
89
90
  end
90
91
  end
92
+
93
+ def zstd
94
+ return nil unless defined?(::Zstd)
95
+ begin
96
+ ::Zstd.decompress(body)
97
+ rescue StandardError
98
+ nil
99
+ end
100
+ end
91
101
  end
92
102
  end
@@ -28,7 +28,7 @@ module HTTParty
28
28
  def self.normalize_param(key, value)
29
29
  normalized_keys = normalize_keys(key, value)
30
30
 
31
- normalized_keys.flatten.each_slice(2).inject(+'') do |string, (k, v)|
31
+ normalized_keys.flatten.each_slice(2).inject(''.dup) do |string, (k, v)|
32
32
  string << "#{ERB::Util.url_encode(k)}=#{ERB::Util.url_encode(v.to_s)}&"
33
33
  end
34
34
  end
@@ -22,7 +22,7 @@ module HTTParty
22
22
  log_request
23
23
  log_response
24
24
 
25
- logger.public_send level, messages.join('\n')
25
+ logger.public_send level, messages.join("\n")
26
26
  end
27
27
 
28
28
  private
@@ -32,15 +32,22 @@ module HTTParty
32
32
 
33
33
  private
34
34
 
35
+ # https://html.spec.whatwg.org/#multipart-form-data
36
+ MULTIPART_FORM_DATA_REPLACEMENT_TABLE = {
37
+ '"' => '%22',
38
+ "\r" => '%0D',
39
+ "\n" => '%0A'
40
+ }.freeze
41
+
35
42
  def generate_multipart
36
43
  normalized_params = params.flat_map { |key, value| HashConversions.normalize_keys(key, value) }
37
44
 
38
- multipart = normalized_params.inject(+'') do |memo, (key, value)|
45
+ multipart = normalized_params.inject(''.dup) do |memo, (key, value)|
39
46
  memo << "--#{boundary}#{NEWLINE}"
40
47
  memo << %(Content-Disposition: form-data; name="#{key}")
41
48
  # value.path is used to support ActionDispatch::Http::UploadedFile
42
49
  # https://github.com/jnunemaker/httparty/pull/585
43
- memo << %(; filename="#{file_name(value)}") if file?(value)
50
+ memo << %(; filename="#{file_name(value).gsub(/["\r\n]/, MULTIPART_FORM_DATA_REPLACEMENT_TABLE)}") if file?(value)
44
51
  memo << NEWLINE
45
52
  memo << "Content-Type: #{content_type(value)}#{NEWLINE}" if file?(value)
46
53
  memo << NEWLINE
@@ -84,8 +91,8 @@ module HTTParty
84
91
 
85
92
  def content_type(object)
86
93
  return object.content_type if object.respond_to?(:content_type)
87
- mime = MIME::Types.type_for(object.path)
88
- mime.empty? ? 'application/octet-stream' : mime[0].content_type
94
+ mime = MiniMime.lookup_by_filename(object.path)
95
+ mime ? mime.content_type : 'application/octet-stream'
89
96
  end
90
97
 
91
98
  def file_name(object)
@@ -46,6 +46,15 @@ module HTTParty
46
46
  end.flatten.join('&')
47
47
  end
48
48
 
49
+ def self._load(data)
50
+ http_method, path, options, last_response, last_uri, raw_request = Marshal.load(data)
51
+ instance = new(http_method, path, options)
52
+ instance.last_response = last_response
53
+ instance.last_uri = last_uri
54
+ instance.instance_variable_set("@raw_request", raw_request)
55
+ instance
56
+ end
57
+
49
58
  attr_accessor :http_method, :options, :last_response, :redirect, :last_uri
50
59
  attr_reader :path
51
60
 
@@ -175,6 +184,13 @@ module HTTParty
175
184
  @raw_request.body
176
185
  end
177
186
 
187
+ def _dump(_level)
188
+ opts = options.dup
189
+ opts.delete(:logger)
190
+ opts.delete(:parser) if opts[:parser] && opts[:parser].is_a?(Proc)
191
+ Marshal.dump([http_method, path, opts, last_response, @last_uri, @raw_request])
192
+ end
193
+
178
194
  private
179
195
 
180
196
  def http
@@ -5,7 +5,7 @@ module HTTParty
5
5
  attr_reader :text, :content_type, :assume_utf16_is_big_endian
6
6
 
7
7
  def initialize(text, assume_utf16_is_big_endian: true, content_type: nil)
8
- @text = text.dup
8
+ @text = +text
9
9
  @content_type = content_type
10
10
  @assume_utf16_is_big_endian = assume_utf16_is_big_endian
11
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTParty
4
- VERSION = '0.19.0'
4
+ VERSION = '0.21.0'
5
5
  end
data/lib/httparty.rb CHANGED
@@ -2,11 +2,10 @@
2
2
 
3
3
  require 'pathname'
4
4
  require 'net/http'
5
- require 'net/https'
6
5
  require 'uri'
7
6
  require 'zlib'
8
7
  require 'multi_xml'
9
- require 'mime/types'
8
+ require 'mini_mime'
10
9
  require 'json'
11
10
  require 'csv'
12
11
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  - Sandro Turriate
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-09 00:00:00.000000000 Z
12
+ date: 2022-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_xml
@@ -26,19 +26,19 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: 0.5.2
28
28
  - !ruby/object:Gem::Dependency
29
- name: mime-types
29
+ name: mini_mime
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '3.0'
34
+ version: 1.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '3.0'
41
+ version: 1.0.0
42
42
  description: Makes http fun! Also, makes consuming restful web services dead easy.
43
43
  email:
44
44
  - nunemaker@gmail.com
@@ -52,7 +52,6 @@ files:
52
52
  - ".gitignore"
53
53
  - ".rubocop.yml"
54
54
  - ".rubocop_todo.yml"
55
- - ".simplecov"
56
55
  - CONTRIBUTING.md
57
56
  - Changelog.md
58
57
  - Gemfile
@@ -124,15 +123,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
123
  requirements:
125
124
  - - ">="
126
125
  - !ruby/object:Gem::Version
127
- version: 2.0.0
126
+ version: 2.3.0
128
127
  required_rubygems_version: !ruby/object:Gem::Requirement
129
128
  requirements:
130
129
  - - ">="
131
130
  - !ruby/object:Gem::Version
132
131
  version: '0'
133
132
  requirements: []
134
- rubygems_version: 3.0.3
135
- signing_key:
133
+ rubygems_version: 3.3.7
134
+ signing_key:
136
135
  specification_version: 4
137
136
  summary: Makes http fun! Also, makes consuming restful web services dead easy.
138
137
  test_files: []
data/.simplecov DELETED
@@ -1 +0,0 @@
1
- SimpleCov.start "test_frameworks"