Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove multipart middleware and all its documentation and tests #1357

Merged
merged 3 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ gem 'jruby-openssl', '~> 0.11.0', platforms: :jruby

group :development, :test do
gem 'coveralls_reborn', require: false
gem 'multipart-parser'
gem 'pry'
gem 'rack', '~> 2.2'
gem 'rake'
Expand Down
30 changes: 28 additions & 2 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ So don't fret yet! We're doing our best to support our `faraday_middleware` user
It will obviously take time for some of the middleware in `faraday_middleware` to make its way into a separate gem, so we appreciate this might be an upgrade obstacle for some. However this is part of an effort to focus the core team resources tackling the most requested features.
We'll be listening to the community and prioritize middleware that are most used, and will be welcoming contributors who want to become owners of the middleware when these become separate from the `faraday_middleware` repo.

### Bundled middleware moved out

Moving middleware into its own gem makes sense not only for `faraday_middleware`, but also for middleware bundled with Faraday.
As of v2.0, the `retry` and `multipart` middleware have been moved to separate `faraday-retry` and `faraday-multipart` gems.
These have been identified as good candidates due to their complexity and external dependencies.
Thanks to this change, we were able to make Faraday 2.0 completely dependency free 🎉 (the only exception being `ruby2_keywords`, which will be necessary only while we keep supporting Ruby 2.6).

#### So what should I do if I currently use the `retry` or `multipart` middleware?

Upgrading is pretty simple, because the middleware was simply moved out to external gems.
All you need to do is to add them to your gemfile (either `faraday-retry` or `faraday-multipart` and require them before usage:

```ruby
# Gemfile
gem 'faraday-multipart'
gem 'faraday-retry'

# Connection initializer
require 'faraday/retry'
require 'faraday/multipart

conn = Faraday.new(url) do |f|
f.request :multipart
f.request :retry
# ...
end
```

### Autoloading and dependencies

Faraday has until now provided and relied on a complex dynamic dependencies system.
Expand All @@ -84,9 +112,7 @@ For more details, see https://github.com/lostisland/faraday/pull/1306

* Rename `Faraday::Request#method` to `#http_method`.
* Remove `Faraday::Response::Middleware`. You can now use the new `on_complete` callback provided by `Faraday::Middleware`.
* Drop `Faraday::UploadIO` in favour of `Faraday::FilePart`.
* `Faraday.default_connection_options` will now be deep-merged into new connections to avoid overriding them (e.g. headers).
* Retry middleware has been moved to a separate `faraday-retry` gem.
* `Faraday::Builder#build` method is not exposed through `Faraday::Connection` anymore and does not reset the handlers if called multiple times. This method should be used internally only.

## Faraday 1.0
Expand Down
25 changes: 8 additions & 17 deletions docs/middleware/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,23 @@ Here's a more realistic example:

```ruby
Faraday.new(...) do |conn|
# POST/PUT params encoders:
conn.request :multipart
# POST/PUT params encoder
conn.request :url_encoded

# Last middleware must be the adapter:
# Logging of requests/responses
conn.response :logger

# Last middleware must be the adapter
conn.adapter :typhoeus
end
```

This request middleware setup affects POST/PUT requests in the following way:

1. `Request::Multipart` checks for files in the payload, otherwise leaves
everything untouched;
2. `Request::UrlEncoded` encodes as "application/x-www-form-urlencoded" if not
already encoded or of another type
1. `Request::UrlEncoded` encodes as "application/x-www-form-urlencoded" if not
already encoded or of another type.
2. `Response::Logger' logs request and response headers, can be configured to log bodies as well.

Swapping middleware means giving the other priority. Specifying the
"Content-Type" for the request is explicitly stating which middleware should
process it.

For example:

```ruby
# uploading a file:
payload[:profile_pic] = Faraday::FilePart.new('/path/to/avatar.jpg', 'image/jpeg')

# "Multipart" middleware detects files and encodes with "multipart/form-data":
conn.put '/profile', payload
```
3 changes: 0 additions & 3 deletions docs/middleware/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ content type.
* [`BasicAuthentication`][authentication] sets the `Authorization` header to the `user:password`
base64 representation.
* [`TokenAuthentication`][authentication] sets the `Authorization` header to the specified token.
* [`Multipart`][multipart] converts a `Faraday::Request#body` hash of key/value pairs into a
multipart form request.
* [`UrlEncoded`][url_encoded] converts a `Faraday::Request#body` hash of key/value pairs into a url-encoded request body.
* [`Json Request`][json-request] converts a `Faraday::Request#body` hash of key/value pairs into a JSON request body.
* [`Json Response`][json-response] parses response body into a hash of key/value pairs.
Expand All @@ -42,7 +40,6 @@ before returning it.


[authentication]: ./authentication
[multipart]: ./multipart
[url_encoded]: ./url-encoded
[json-request]: ./json-request
[instrumentation]: ./instrumentation
Expand Down
4 changes: 2 additions & 2 deletions docs/middleware/request/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ layout: documentation
title: "Authentication Middleware"
permalink: /middleware/authentication
hide: true
next_name: Multipart Middleware
next_link: ./multipart
next_name: UrlEncoded Middleware
next_link: ./url-encoded
top_name: Back to Middleware
top_link: ./list
---
Expand Down
68 changes: 0 additions & 68 deletions docs/middleware/request/multipart.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/middleware/request/url_encoded.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ layout: documentation
title: "UrlEncoded Middleware"
permalink: /middleware/url-encoded
hide: true
prev_name: Multipart Middleware
prev_link: ./multipart
prev_name: Authentication Middleware
prev_link: ./authentication
next_name: JSON Request Middleware
next_link: ./json-request
top_name: Back to Middleware
Expand Down
6 changes: 2 additions & 4 deletions docs/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,15 @@ response = conn.post('post', '{"boom": "zap"}',

#### Posting Forms

Faraday will automatically convert key/value hashes into proper form bodies.
Faraday will automatically convert key/value hashes into proper form bodies
thanks to the `url_encoded` middleware included in the default connection.

```ruby
# POST 'application/x-www-form-urlencoded' content
response = conn.post('post', boom: 'zap')
# => POST 'boom=zap' to http://httpbingo.org/post
```

Faraday can also [upload files][multipart].

### Detailed HTTP Requests

Faraday supports a longer style for making requests. This is handy if you need
Expand Down Expand Up @@ -185,4 +184,3 @@ Note that if you create your own connection with middleware, it won't encode
form bodies unless you too include the [`:url_encoded`](encoding) middleware!

[encoding]: ../middleware/url-encoded
[multipart]: ../middleware/multipart
1 change: 0 additions & 1 deletion faraday.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.6'

spec.add_dependency 'multipart-post', '>= 1.2', '< 3'
spec.add_dependency 'ruby2_keywords', '>= 0.0.4'

# Includes `examples` and `spec` to allow external adapter gems to run Faraday unit and integration tests
Expand Down
2 changes: 0 additions & 2 deletions lib/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
require 'faraday/adapter'
require 'faraday/request'
require 'faraday/response'
require 'faraday/file_part'
require 'faraday/param_part'

# This is the main namespace for Faraday.
#
Expand Down
122 changes: 0 additions & 122 deletions lib/faraday/file_part.rb

This file was deleted.

Loading