Skip to content

Commit

Permalink
Merge 4a9c23a into 93a693b
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Jan 2, 2022
2 parents 93a693b + 4a9c23a commit d206fbe
Show file tree
Hide file tree
Showing 20 changed files with 15 additions and 820 deletions.
1 change: 0 additions & 1 deletion Gemfile
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
3 changes: 1 addition & 2 deletions UPGRADING.md
Expand Up @@ -84,9 +84,8 @@ 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.
* Retry and Multipart middleware have been moved to separate `faraday-retry` and `faraday-multipart` gems.
* `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
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
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
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
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
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
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
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.

53 changes: 0 additions & 53 deletions lib/faraday/param_part.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/faraday/request.rb
Expand Up @@ -133,5 +133,4 @@ def to_env(connection)
require 'faraday/request/authorization'
require 'faraday/request/instrumentation'
require 'faraday/request/json'
require 'faraday/request/multipart'
require 'faraday/request/url_encoded'

0 comments on commit d206fbe

Please sign in to comment.