Skip to content

Instantly share code, notes, and snippets.

@DmytroVasin
Created December 23, 2017 21:26
Show Gist options
  • Save DmytroVasin/e3c2d2e73ad872d9d0e6a0e1a6c400b5 to your computer and use it in GitHub Desktop.
Save DmytroVasin/e3c2d2e73ad872d9d0e6a0e1a6c400b5 to your computer and use it in GitHub Desktop.
em+stream
require 'faraday'
require 'pluck_all'
require 'eventmachine'
require 'em-http-request'
require 'pry'
EventMachine.run {
total_size = 0
p 'start'
conn = EventMachine::HttpRequest.new('https://mypornprofile.com/video_thumbnails/21288_10576_3086ad7206d8e5a7e5edb8f7239d081f.jpg')
# conn = EventMachine::HttpRequest.new('https://mypornprofile.com/video_thumbnails/20368_13853_77d42ff0e2c91ef632cc60e289818355.jpg')
http = conn.get
http.headers { |hash|
p [:headers, hash]
# binding.pry
# EventMachine.stop
}
http.stream do |chunk|
puts "stream #{chunk.size} bytes (total = #{total_size})"
total_size += chunk.size
conn.close('Body too large') if total_size > 100_000
end
http.errback { |h|
p '!!!!!!!!!!!!!'
EventMachine.stop
}
http.callback { |h|
p '??????????????'
EventMachine.stop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment