faraday-multipart 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bd506d533ad9203184a3dac476941919f349e4565e81fa1521b8bc022f60f64
|
4
|
+
data.tar.gz: b34ae2db7c7d54de96ef743d2568c31066f2160ccc120d1b719e3fe6eb7141b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cb034f5f9fc6dbbb71225a967dcb81fdffdde7b7cd7790fe019e4f4c1b7e242f9df1726c6f2f8f0f33555d88613a6e6d75ebb50a638e939e9618d6dc7a65161
|
7
|
+
data.tar.gz: 37e5c0998d0ad5d40cd03cf3cdaf98e1f9473451035553bf61d1a8ba107ee53f62311080035520044b0b3053e1cb33bd2cd781d3480d11206197e96adc579099
|
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
|
-
[![
|
3
|
+
[![ci](https://github.com/lostisland/faraday-multipart/actions/workflows/ci.yaml/badge.svg)](https://github.com/lostisland/faraday-multipart/actions/workflows/ci.yaml)
|
4
4
|
[![Gem](https://img.shields.io/gem/v/faraday-multipart.svg?style=flat-square)](https://rubygems.org/gems/faraday-multipart)
|
5
5
|
[![License](https://img.shields.io/github/license/lostisland/faraday-multipart.svg?style=flat-square)](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,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-multipart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Giuffrida
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2'
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2'
|
26
|
+
version: '2.0'
|
27
27
|
description: 'Perform multipart-post requests using Faraday.
|
28
28
|
|
29
29
|
'
|
@@ -46,12 +46,12 @@ licenses:
|
|
46
46
|
- MIT
|
47
47
|
metadata:
|
48
48
|
bug_tracker_uri: https://github.com/lostisland/faraday-multipart/issues
|
49
|
-
changelog_uri: https://github.com/lostisland/faraday-multipart/blob/v1.0
|
50
|
-
documentation_uri: http://www.rubydoc.info/gems/faraday-multipart/1.0
|
49
|
+
changelog_uri: https://github.com/lostisland/faraday-multipart/blob/v1.1.0/CHANGELOG.md
|
50
|
+
documentation_uri: http://www.rubydoc.info/gems/faraday-multipart/1.1.0
|
51
51
|
homepage_uri: https://github.com/lostisland/faraday-multipart
|
52
52
|
source_code_uri: https://github.com/lostisland/faraday-multipart
|
53
53
|
wiki_uri: https://github.com/lostisland/faraday-multipart/wiki
|
54
|
-
post_install_message:
|
54
|
+
post_install_message:
|
55
55
|
rdoc_options: []
|
56
56
|
require_paths:
|
57
57
|
- lib
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubygems_version: 3.1.6
|
73
|
-
signing_key:
|
73
|
+
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Perform multipart-post requests using Faraday.
|
76
76
|
test_files: []
|