Skip to content

Instantly share code, notes, and snippets.

@wconrad
Last active July 9, 2021 13:32
Show Gist options
  • Save wconrad/c6885b2a6dd6494880964c3d6fb8e1f1 to your computer and use it in GitHub Desktop.
Save wconrad/c6885b2a6dd6494880964c3d6fb8e1f1 to your computer and use it in GitHub Desktop.
Demonstrate alleged bug in the faraday gem, wherein streaming appears to be broken by persistence
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "faraday", "1.5.0"
gem "net-http-persistent", "4.0.1"
GEM
remote: https://rubygems.org/
specs:
connection_pool (2.2.5)
faraday (1.5.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-patron (~> 1.0)
multipart-post (>= 1.2, < 3)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.1.0)
faraday-patron (1.0.0)
multipart-post (2.1.1)
net-http-persistent (4.0.1)
connection_pool (~> 2.2)
ruby2_keywords (0.0.4)
PLATFORMS
x86_64-linux
DEPENDENCIES
faraday (= 1.5.0)
net-http-persistent (= 4.0.1)
BUNDLED WITH
2.2.15
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "faraday"
connection = Faraday.new("https://google.com") do |f|
f.adapter :net_http_persistent
end
connection.get("/") do |request|
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
puts "Received #{overall_received_bytes} characters"
end
end
# => (no output)
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "faraday"
connection = Faraday.new("https://google.com")
connection.get("/") do |request|
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
puts "Received #{overall_received_bytes} characters"
end
end
# => Received 220 characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment