httparty 0.20.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: bde34a85d8b010341759c1b2b42dfe58cad693c39f047b9803ac90afbc13290b
4
- data.tar.gz: b5248420c90ea545dfa9e6e234d6c597b4c7306dfc8d58ff94dca82e405e0ed1
3
+ metadata.gz: 9dccd9b1a1fa3f98ca96da312ccdf19371418815a556b1443acac322a8ae4e15
4
+ data.tar.gz: 61f75235d1dcf4e1e38cbab62869aeeff28de9d0dc27fad30c7ca11d6355cd0d
5
5
  SHA512:
6
- metadata.gz: 13316910a85a75d1204c64be41e995475b26abf9aad1165c06349c296d0b3f0f6ae644b00d8bcf14adc3d9a11659bffd060a5101dc88718af74d0324adde9e30
7
- data.tar.gz: 668fac0ca6a513e64dead9b633ecb12c4ff926cb017e4e7e244249cfb361f93e1aa515ef3fb6b80e6245264e7da38d0599abec9931c5b33b88d7235b966b0aa1
6
+ metadata.gz: e47fce0ce8b6c4fe97ee0335b4f0544bc039755f12f0c2aac9f47e901739fd172390a3dc01f070d6799b1af335293b5d09a66514deb0810dfafc37f25d2f3c81
7
+ data.tar.gz: 9aa37800410a58a60ca751de44eed1026514b26c408a1f890b48a8f0049c814052a70a55343d3798c3d4d59ca9b157257c1fa83240200d283ba374a9b62db2ef
@@ -11,9 +11,12 @@ jobs:
11
11
  - 2.5
12
12
  - 2.6
13
13
  - 2.7
14
+ - '3.0' # Quoted, to avoid YAML float 3.0 interplated to "3"
15
+ - 3.1
16
+ - 3.2
14
17
  steps:
15
18
  - name: Check out repository code
16
- uses: actions/checkout@v2
19
+ uses: actions/checkout@v3
17
20
  - name: Set up Ruby
18
21
  uses: ruby/setup-ruby@v1
19
22
  with:
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,9 @@
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
+
1
7
  ## 0.20.0
2
8
 
3
9
  Breaking changes
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
 
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
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
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!"
@@ -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
@@ -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,6 +32,13 @@ 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
 
@@ -40,7 +47,7 @@ module HTTParty
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)
@@ -47,8 +47,12 @@ module HTTParty
47
47
  end
48
48
 
49
49
  def self._load(data)
50
- http_method, path, options = Marshal.load(data)
51
- new(http_method, path, options)
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
52
56
  end
53
57
 
54
58
  attr_accessor :http_method, :options, :last_response, :redirect, :last_uri
@@ -184,7 +188,7 @@ module HTTParty
184
188
  opts = options.dup
185
189
  opts.delete(:logger)
186
190
  opts.delete(:parser) if opts[:parser] && opts[:parser].is_a?(Proc)
187
- Marshal.dump([http_method, path, opts])
191
+ Marshal.dump([http_method, path, opts, last_response, @last_uri, @raw_request])
188
192
  end
189
193
 
190
194
  private
@@ -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.20.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.20.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-29 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
@@ -131,8 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
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"