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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 003f27fac04888822e0601b1ff9e67a374d3a07a77cdaa2a59e929956228fe6c
4
- data.tar.gz: e8bf33e1089e8e3f4b9b2326edcd2e2bb2c32f87bb89b2336b798fed5806c942
3
+ metadata.gz: c32bdcc8a56bde071bf290f431a4b9f7770607151f10f47741c96a811496dd08
4
+ data.tar.gz: c9f96a258eb0dcb02106ed07a4c2b35ef4edf96d8fe2c2fb9554810b361623c1
5
5
  SHA512:
6
- metadata.gz: 8cc6c3ac2a717c353e035f4de9b7486142df5c6266f2464db3dbd533fa4d8236f64498e7cf00b22d8afc3d17fd34d5d387d5665908454061495199ebb031cab7
7
- data.tar.gz: b59ce976a29a837ff68953db793d28565d8a5579c808d8ce758cdb4663a0bca1e7ce802ab98152874b79dcaea47faa9177578e1b1eae464c5701ecf5dbe20751
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) (2022-06-07)
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
- [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/lostisland/faraday-multipart/ci)](https://github.com/lostisland/faraday-multipart/actions?query=branch%3Amain)
3
+ [![ci](https://github.com/lostisland/faraday-multipart/actions/workflows/ci.yml/badge.svg)](https://github.com/lostisland/faraday-multipart/actions/workflows/ci.yml)
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::Request::UrlEncoded
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 == self.class.mime_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
@@ -3,7 +3,7 @@
3
3
  module Faraday
4
4
  # #:nodoc:
5
5
  module Multipart
6
- VERSION = '1.0.4'
6
+ VERSION = '1.1.1'
7
7
 
8
8
  def self.multipart_post_version
9
9
  require 'multipart/post/version'
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.0.4
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: 2022-06-07 00:00:00.000000000 Z
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.0.4/CHANGELOG.md
50
- documentation_uri: http://www.rubydoc.info/gems/faraday-multipart/1.0.4
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.1.6
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: []