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

Add support for the new Faraday streaming API #26

Merged
merged 1 commit into from
Aug 8, 2022
Merged

Conversation

iMacTia
Copy link
Member

@iMacTia iMacTia commented Aug 8, 2022

Description

Add support for the new Faraday streaming API (see original issue)

Testing

Tested with the following script (adapter from the one in the issue)

require 'webmock'
require 'faraday'
require 'faraday/net_http'
require 'faraday/follow_redirects'

include WebMock::API
WebMock.enable!

stub_request(:get, 'https://www.example.com')
  .to_return(body: 'You are being redirected',
             status: [302, 'Content moved'],
             headers: { 'Location' => 'https://example.com' })

stub_request(:get, 'https://example.com')
  .to_return(body: 'You have arrived')

client = Faraday.new do |f|
  f.use Faraday::FollowRedirects::Middleware
end

client.get('https://www.example.com') do |req|
  req.options.on_data = proc do |chunk, _size, env|
    puts "got: #{chunk}" if env.status < 300
  end
end

this now outputs only the following:

got: You have arrived

Additional Notes

This change relies on new APIs introduced with Faraday 2.5 and is therefore incompatible with Faraday 2.4 and prior.
For this reason, these changes need to be released as a new v3.0 of the adapter, to avoid existing applications erroneously pulling this version while still using Faraday 2.4.

This problem affects this adapter only as it's a dependency of Faraday (default adapter).
Other adapters can specify the version of faraday in their Gemfile and therefore won't require a new major version.

@iMacTia iMacTia self-assigned this Aug 8, 2022
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.

👍 Thanks for providing the additional context in the PR description, that helps.

@iMacTia
Copy link
Member Author

iMacTia commented Aug 8, 2022

Thanks for the quick review 🚀 !

@iMacTia iMacTia merged commit 72c65ca into main Aug 8, 2022
@iMacTia iMacTia deleted the mg/new-streaming-api branch August 8, 2022 12:57
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.

None yet

2 participants