基本的にこれを行うコードがいくつかあります。ここで、varurlsは文字列の配列です。これは蒸留版ですが、要点を示しているはずです。
require 'rubygems'
require 'typhoeus'
require 'json'
require 'socket'
def hit_http_urls(urls)
hydra = Typhoeus::Hydra.new
hydra.disable_memoization
urls.each do |url|
req = Typhoeus::Request.new(url,
:disable_ssl_peer_verification => true,
:disable_ssl_host_verification => true,
:ssl_version => :sslv3,
:headers=>{'User-Agent' => 'athingy', 'Content-Type' => 'text/xml; charset=utf-8'},
:timeout => 10)
req.on_complete { |res|
puts res.body.length
}
hydra.queue(req)
end
hydra.run
end
問題は、1つ(または複数)のURLがメガバイト単位で応答する可能性があることです。この関数はほとんど同じURLのグループでループで実行されるため、これは望ましくありません。どういうわけかハード制限後にデータの受信を停止する方法はありますか?:max_response_sizeか何かのように?
hydra / typhoeusのrubydocsを見てきました:http: //rubydoc.info/github/dbalatero/typhoeus/master/Typhoeus/Hydra
http://rubydoc.info/github/dbalatero/typhoeus/master/Typhoeus/Request
http://rubydoc.info/gems/typhoeus/0.4.1/file/README.md
しかし、彼らは私に応答の体のサイズを制限する方法を教えていないようです。これは可能ですか?