faraday-multipart 1.0.4 → 1.1.1
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/CHANGELOG.md +3 -1
- data/README.md +13 -1
- data/lib/faraday/multipart/middleware.rb +36 -4
- data/lib/faraday/multipart/version.rb +1 -1
- metadata +7 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c32bdcc8a56bde071bf290f431a4b9f7770607151f10f47741c96a811496dd08
|
4
|
+
data.tar.gz: c9f96a258eb0dcb02106ed07a4c2b35ef4edf96d8fe2c2fb9554810b361623c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88bec52f2c139c1a91e8cbe2cd5a8e84b36721998c567aa244b629d45b961ea68e134d9071840f636017973822720c8d607cdee2649d0857c45087f8a6c5d070
|
7
|
+
data.tar.gz: 881d3bc91852a8ea2c2051cba449b059d5a56f6dff7c09c6216a089e522ee82562f53d57d77aa1f2ae2d03672842263fd55ff7e0c819e303b6894203a369b34e
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [1.0.4](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.
|
3
|
+
## [1.0.4](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.4) (2022-06-07)
|
4
4
|
|
5
5
|
### What's Changed
|
6
6
|
|
@@ -8,6 +8,8 @@
|
|
8
8
|
* Change references to `UploadIO` and `Parts` according to class reorganization in the 'multipart-post' gem 2.2.0 (see [multipart-post gem PR #89](https://github.com/socketry/multipart-post/pull/89))
|
9
9
|
* Introduce a backwards compatible safeguard so the gem still works with previous 'multipart-post' 2.x releases.
|
10
10
|
|
11
|
+
**Full Changelog**: https://github.com/lostisland/faraday-multipart/compare/v1.0.3...v1.0.4
|
12
|
+
|
11
13
|
## [1.0.3](https://github.com/lostisland/faraday-multipart/releases/tag/v1.0.3) (2022-01-08)
|
12
14
|
|
13
15
|
### What's Changed
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Faraday Multipart
|
2
2
|
|
3
|
-
[](https://github.com/lostisland/faraday-multipart/actions/workflows/ci.yml)
|
4
4
|
[](https://rubygems.org/gems/faraday-multipart)
|
5
5
|
[](LICENSE.md)
|
6
6
|
|
@@ -51,6 +51,18 @@ conn = Faraday.new(...) do |f|
|
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
54
|
+
If you need to [specify a different content type for the multipart
|
55
|
+
request](https://www.iana.org/assignments/media-types/media-types.xhtml#multipart),
|
56
|
+
you can do so by providing the `content_type` option but it must start with
|
57
|
+
`multipart/`
|
58
|
+
otherwise it will default to `multipart/form-data`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
conn = Faraday.new(...) do |f|
|
62
|
+
f.request :multipart, content_type: 'multipart/mixed'
|
63
|
+
# ...
|
64
|
+
end
|
65
|
+
```
|
54
66
|
|
55
67
|
Payload can be a mix of POST data and multipart values.
|
56
68
|
|
@@ -5,11 +5,10 @@ require 'securerandom'
|
|
5
5
|
module Faraday
|
6
6
|
module Multipart
|
7
7
|
# Middleware for supporting multi-part requests.
|
8
|
-
class Middleware < Faraday::
|
8
|
+
class Middleware < Faraday::Middleware
|
9
|
+
CONTENT_TYPE = 'Content-Type'
|
9
10
|
DEFAULT_BOUNDARY_PREFIX = '-----------RubyMultipartPost'
|
10
11
|
|
11
|
-
self.mime_type = 'multipart/form-data'
|
12
|
-
|
13
12
|
def initialize(app = nil, options = {})
|
14
13
|
super(app)
|
15
14
|
@options = options
|
@@ -28,15 +27,37 @@ module Faraday
|
|
28
27
|
@app.call env
|
29
28
|
end
|
30
29
|
|
30
|
+
private
|
31
|
+
|
32
|
+
# @param env [Faraday::Env]
|
33
|
+
# @yield [request_body] Body of the request
|
34
|
+
def match_content_type(env)
|
35
|
+
return unless process_request?(env)
|
36
|
+
|
37
|
+
env.request_headers[CONTENT_TYPE] ||= mime_type
|
38
|
+
return if env.body.respond_to?(:to_str) || env.body.respond_to?(:read)
|
39
|
+
|
40
|
+
yield(env.body)
|
41
|
+
end
|
42
|
+
|
31
43
|
# @param env [Faraday::Env]
|
32
44
|
def process_request?(env)
|
33
45
|
type = request_type(env)
|
34
46
|
env.body.respond_to?(:each_key) && !env.body.empty? && (
|
35
47
|
(type.empty? && has_multipart?(env.body)) ||
|
36
|
-
(type ==
|
48
|
+
(type == mime_type)
|
37
49
|
)
|
38
50
|
end
|
39
51
|
|
52
|
+
# @param env [Faraday::Env]
|
53
|
+
#
|
54
|
+
# @return [String]
|
55
|
+
def request_type(env)
|
56
|
+
type = env.request_headers[CONTENT_TYPE].to_s
|
57
|
+
type = type.split(';', 2).first if type.index(';')
|
58
|
+
type
|
59
|
+
end
|
60
|
+
|
40
61
|
# Returns true if obj is an enumerable with values that are multipart.
|
41
62
|
#
|
42
63
|
# @param obj [Object]
|
@@ -97,6 +118,17 @@ module Faraday
|
|
97
118
|
end
|
98
119
|
end
|
99
120
|
end
|
121
|
+
|
122
|
+
# Determines and provides the multipart mime type for the request.
|
123
|
+
#
|
124
|
+
# @return [String] the multipart mime type
|
125
|
+
def mime_type
|
126
|
+
@mime_type ||= if @options[:content_type].to_s.match?(%r{\Amultipart/.+})
|
127
|
+
@options[:content_type].to_s
|
128
|
+
else
|
129
|
+
'multipart/form-data'
|
130
|
+
end
|
131
|
+
end
|
100
132
|
end
|
101
133
|
end
|
102
134
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-multipart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Giuffrida
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: multipart-post
|
@@ -16,14 +15,14 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2'
|
18
|
+
version: '2.0'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2'
|
25
|
+
version: '2.0'
|
27
26
|
description: 'Perform multipart-post requests using Faraday.
|
28
27
|
|
29
28
|
'
|
@@ -46,12 +45,11 @@ licenses:
|
|
46
45
|
- MIT
|
47
46
|
metadata:
|
48
47
|
bug_tracker_uri: https://github.com/lostisland/faraday-multipart/issues
|
49
|
-
changelog_uri: https://github.com/lostisland/faraday-multipart/blob/v1.
|
50
|
-
documentation_uri: http://www.rubydoc.info/gems/faraday-multipart/1.
|
48
|
+
changelog_uri: https://github.com/lostisland/faraday-multipart/blob/v1.1.1/CHANGELOG.md
|
49
|
+
documentation_uri: http://www.rubydoc.info/gems/faraday-multipart/1.1.1
|
51
50
|
homepage_uri: https://github.com/lostisland/faraday-multipart
|
52
51
|
source_code_uri: https://github.com/lostisland/faraday-multipart
|
53
52
|
wiki_uri: https://github.com/lostisland/faraday-multipart/wiki
|
54
|
-
post_install_message:
|
55
53
|
rdoc_options: []
|
56
54
|
require_paths:
|
57
55
|
- lib
|
@@ -69,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
67
|
- !ruby/object:Gem::Version
|
70
68
|
version: '0'
|
71
69
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
-
signing_key:
|
70
|
+
rubygems_version: 3.6.7
|
74
71
|
specification_version: 4
|
75
72
|
summary: Perform multipart-post requests using Faraday.
|
76
73
|
test_files: []
|