Skip to content

Instantly share code, notes, and snippets.

@bkimble
Created October 12, 2011 18:25
Show Gist options
  • Save bkimble/1282088 to your computer and use it in GitHub Desktop.
Save bkimble/1282088 to your computer and use it in GitHub Desktop.
Reproduction process for Typhoeus max concurrency issues with zlib
#!/usr/bin/env ruby
require 'rubygems'
require 'typhoeus'
hydra = Typhoeus::Hydra.new(:max_concurrency => 1)
hydra.disable_memoization
typh_options = {:headers => {"Accept-Encoding" => "deflate, gzip"}, :method => :get, :verbose => false}
r1 = Typhoeus::Request.new("http://www.yahoo.com/", typh_options)
r2 = Typhoeus::Request.new("http://www.yahoo.com/", typh_options)
r3 = Typhoeus::Request.new("http://www.yahoo.com/", typh_options)
hydra.queue(r1)
hydra.queue(r2)
hydra.queue(r3)
hydra.run
expected_begin_line = "<!DOCTYPE html>"
[r1,r2,r3].each_with_index do |r,i|
puts '-' * 80
puts "Request #{i+1}\n\n"
puts "Url: #{r.url}\n\n"
puts "Headers sent: #{r.headers.inspect}\n\n"
puts "Headers received: #{r.response.headers_hash.inspect}\n\n"
matched = r.response.body.match(/^#{expected_begin_line}/)
puts "Matches expected beginning line?: " + (matched ? "Yes" : "NO") + "\n\n"
unless matched
puts "Don't know what this response is. It starts with: #{r.response.body[0..80]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment