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

Move json middleware (request and response) from faraday_middleware #1300

Merged
merged 6 commits into from
Aug 9, 2021

Conversation

iMacTia
Copy link
Member

@iMacTia iMacTia commented Aug 7, 2021

Description

The JSON middleware, both request and response ones, are between the most used and require no external dependency since the json module is part of Ruby.
For this reason, we can safely move it inside Faraday.

Tests have also been moved and the Website documentation have been updated.

Todos

List any remaining work that needs to be done, i.e:

  • Tests
  • Documentation

@iMacTia iMacTia self-assigned this Aug 7, 2021
@olleolleolle
Copy link
Member

Ruby 3 seems to have some unwanted behaviour about arguments, is that around kwargs?

@iMacTia
Copy link
Member Author

iMacTia commented Aug 8, 2021

It's the dependency loader, even adding ** to the middleware initializer in the spec doesn't solve the problem completely. I was planning to get rid of it anyway so I'll do that in another PR

@iMacTia
Copy link
Member Author

iMacTia commented Aug 8, 2021

I'm gonna finish this up once #1301 gets merged 👍

Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful!

docs/middleware/list.md Outdated Show resolved Hide resolved
docs/middleware/request/instrumentation.md Outdated Show resolved Hide resolved
docs/middleware/request/json.md Outdated Show resolved Hide resolved
docs/middleware/request/json.md Outdated Show resolved Hide resolved
docs/middleware/request/json.md Outdated Show resolved Hide resolved
docs/middleware/response/logger.md Outdated Show resolved Hide resolved
self.headers = serialised[:headers]
self.path = serialised[:path]
self.params = serialised[:params]
self.options = serialised[:options]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change!


def process_request?(env)
type = request_type(env)
body?(env) && (type.empty? || MIME_TYPE_REGEX =~ type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby version question: Can we use #match? here?

def process_response_type?(env)
type = response_type(env)
@content_types.empty? || @content_types.any? do |pattern|
pattern.is_a?(Regexp) ? type =~ pattern : type == pattern
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, perhaps too, an opportunity for #match?

let(:options) { {} }
let(:headers) { {} }
let(:middleware) do
puts options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is debug output, perhaps it can be removed?

Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@iMacTia iMacTia merged commit 4b6162d into main Aug 9, 2021
@iMacTia iMacTia deleted the move-json-middleware branch August 9, 2021 07:52
iMacTia added a commit that referenced this pull request Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants