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 +4 -4
- data/.github/workflows/ci.yml +12 -14
- data/.gitignore +2 -1
- data/Changelog.md +21 -0
- data/Gemfile +2 -0
- data/Guardfile +3 -2
- data/README.md +2 -2
- data/docs/README.md +25 -5
- data/httparty.gemspec +2 -2
- data/lib/httparty/connection_adapter.rb +1 -1
- data/lib/httparty/decompressor.rb +11 -1
- data/lib/httparty/hash_conversions.rb +1 -1
- data/lib/httparty/logger/curl_formatter.rb +1 -1
- data/lib/httparty/request/body.rb +11 -4
- data/lib/httparty/request.rb +16 -0
- data/lib/httparty/text_encoder.rb +1 -1
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +1 -2
- metadata +11 -12
- data/.simplecov +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9dccd9b1a1fa3f98ca96da312ccdf19371418815a556b1443acac322a8ae4e15
|
|
4
|
+
data.tar.gz: 61f75235d1dcf4e1e38cbab62869aeeff28de9d0dc27fad30c7ca11d6355cd0d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e47fce0ce8b6c4fe97ee0335b4f0544bc039755f12f0c2aac9f47e901739fd172390a3dc01f070d6799b1af335293b5d09a66514deb0810dfafc37f25d2f3c81
|
|
7
|
+
data.tar.gz: 9aa37800410a58a60ca751de44eed1026514b26c408a1f890b48a8f0049c814052a70a55343d3798c3d4d59ca9b157257c1fa83240200d283ba374a9b62db2ef
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -5,24 +5,22 @@ jobs:
|
|
|
5
5
|
runs-on: ubuntu-latest
|
|
6
6
|
strategy:
|
|
7
7
|
matrix:
|
|
8
|
-
ruby:
|
|
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@
|
|
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:
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
21
22
|
with:
|
|
22
23
|
ruby-version: ${{ matrix.ruby }}
|
|
23
|
-
|
|
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
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
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# httparty
|
|
2
2
|
|
|
3
|
-
[](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.
|
|
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
|
|
127
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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.
|
|
16
|
+
s.required_ruby_version = '>= 2.3.0'
|
|
17
17
|
|
|
18
18
|
s.add_dependency 'multi_xml', ">= 0.5.2"
|
|
19
|
-
s.add_dependency
|
|
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
|
|
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(
|
|
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
|
|
@@ -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(
|
|
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 =
|
|
88
|
-
mime
|
|
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)
|
data/lib/httparty/request.rb
CHANGED
|
@@ -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
|
|
8
|
+
@text = +text
|
|
9
9
|
@content_type = content_type
|
|
10
10
|
@assume_utf16_is_big_endian = assume_utf16_is_big_endian
|
|
11
11
|
end
|
data/lib/httparty/version.rb
CHANGED
data/lib/httparty.rb
CHANGED
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.
|
|
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:
|
|
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:
|
|
29
|
+
name: mini_mime
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
|
32
|
-
- - "
|
|
32
|
+
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version:
|
|
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:
|
|
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.
|
|
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.
|
|
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"
|