httparty 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -1
- data/.gitignore +2 -1
- data/Changelog.md +6 -0
- data/Gemfile +2 -0
- data/Guardfile +3 -2
- data/README.md +1 -1
- data/docs/README.md +25 -5
- data/httparty.gemspec +1 -1
- data/lib/httparty/decompressor.rb +11 -1
- data/lib/httparty/logger/curl_formatter.rb +1 -1
- data/lib/httparty/request/body.rb +10 -3
- data/lib/httparty/request.rb +7 -3
- data/lib/httparty/text_encoder.rb +1 -1
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +1 -2
- metadata +10 -11
- 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
@@ -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@
|
19
|
+
uses: actions/checkout@v3
|
17
20
|
- name: Set up Ruby
|
18
21
|
uses: ruby/setup-ruby@v1
|
19
22
|
with:
|
data/.gitignore
CHANGED
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
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# httparty
|
2
2
|
|
3
|
-
[![
|
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
|
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
@@ -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
|
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
|
@@ -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 =
|
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
@@ -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
|
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
|
@@ -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.
|
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"
|