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

Increase Faraday dependency's maximum version to 3.0.0 #19

Merged
merged 2 commits into from
Sep 6, 2022
Merged

Increase Faraday dependency's maximum version to 3.0.0 #19

merged 2 commits into from
Sep 6, 2022

Conversation

hmnhf
Copy link
Contributor

@hmnhf hmnhf commented Aug 29, 2022

Faraday has deprecated its middleware gem since version 2.0.0 and introduced a new built-in JSON middleware. (Which is the only middleware used by rubycent.)

This pull request:

  • Updates Faraday's dependency version to allow using the latest version.

  • Requires the middleware gem only if Faraday's version is older than 2.0.0. (The middleware gem can be removed in the future after changing Faraday dependency's minimum version to 2.0.0.)

  • Fixes a failing test with Faraday versions 2.x. See the commit message of 450ed40 for a detailed explanation.

@FZambia
Copy link
Member

FZambia commented Aug 29, 2022

@hmnhf hello, many thanks for the PR!

I fixed CI issue in 060f20d - please rebase to the latest master.

@prikha Sergey, possibly you could check this out too?

Faraday's middleware has been deprecated since its version 2.0.0 release.
Faraday 2.0.0 has built-in JSON middleware support which is the only middleware used by rubycent.
rubycent still has the middleware dependency to support Faraday versions older than 2.0.0.

https://github.com/lostisland/faraday/blob/main/UPGRADING.md#faraday-middleware-deprecation
Some client tests were failing with this error:
NoMethodError: undefined method `key?' for "{}":String (lib/cent/http.rb:42)

The failure is due to the difference between Faraday middleware's JSON `#parse_response?` implementation,
and Faraday's version 2.0.0 implementation of the now built-in `#parse_response?`.

The middleware parses the body if the body starts with a bracket.
https://github.com/lostisland/faraday_middleware/blob/3f6b113f6a7f71ef05c35a03514bbc08f7993dcf/lib/faraday_middleware/response/parse_json.rb#L35

While, Faraday parses the body if the response Content-Type header matches the configured value. (Default: /\bjson$/)
https://github.com/lostisland/faraday/blob/4816043101ea57f806d0946ed29f252e06d16909/lib/faraday/response/json.rb#L38

This commit fixes the error by adding a "Content-Type: application/json" header to the stubbed response.
@hmnhf
Copy link
Contributor Author

hmnhf commented Aug 29, 2022

@FZambia My pleasure. Rebased the branch with master.

@FZambia FZambia requested a review from prikha August 30, 2022 06:16
@FZambia FZambia merged commit 56721e2 into centrifugal:master Sep 6, 2022
@FZambia
Copy link
Member

FZambia commented Sep 6, 2022

@hmnhf hello, part of v2.1.0 - thanks!

@hmnhf hmnhf deleted the upgrade-faraday branch February 5, 2023 13:52
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