Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* added support for extensive time information per request

* added examples/times.rb
  • Loading branch information...
commit 7eb00d95f963edd865988ca937a52dbf25bf9446 1 parent e0c6012
@Zapotek Zapotek authored
View
40 examples/times.rb
@@ -0,0 +1,40 @@
+require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
+
+hydra = Typhoeus::Hydra.new
+hydra.disable_memoization
+
+urls = [
+ 'http://google.com',
+ 'http://testphp.vulnweb.com',
+ 'http://demo.testfire.net',
+ 'http://example.net',
+]
+
+10.times {
+ |i|
+
+ req = Typhoeus::Request.new( urls[ i % urls.size], :max_concurrency => 10 )
+ req.on_complete {
+ |res|
+ puts 'URL: ' + res.effective_url
+ puts 'Time: ' + res.time.to_s
+ puts 'Connect time: ' + res.connect_time.to_s
+ puts 'App connect time: ' + res.app_connect_time.to_s
+ puts 'Start transfer time: ' + res.start_transfer_time.to_s
+ puts 'Pre transfer time: ' + res.pretransfer_time.to_s
+ puts '-------------'
+ }
+
+ hydra.queue( req )
+ puts 'Queued: ' + req.url
+}
+
+puts
+puts 'Harvesting responses...'
+puts
+
+hydra.run
+
+puts
+puts 'Done.'
+puts
View
34 lib/typhoeus/easy.rb
@@ -43,10 +43,16 @@ class Easy
:CURLOPT_CAPATH => 10097
}
INFO_VALUES = {
- :CURLINFO_RESPONSE_CODE => 2097154,
- :CURLINFO_TOTAL_TIME => 3145731,
- :CURLINFO_HTTPAUTH_AVAIL => 0x200000 + 23,
- :CURLINFO_EFFECTIVE_URL => 0x100000 + 1
+ :CURLINFO_RESPONSE_CODE => 2097154,
+ :CURLINFO_TOTAL_TIME => 3145731,
+ :CURLINFO_HTTPAUTH_AVAIL => 0x200000 + 23,
+ :CURLINFO_EFFECTIVE_URL => 0x100000 + 1,
+ :CURLINFO_NAMELOOKUP_TIME => 0x300000 + 4,
+ :CURLINFO_CONNECT_TIME => 0x300000 + 5,
+ :CURLINFO_PRETRANSFER_TIME => 0x300000 + 6,
+ :CURLINFO_STARTTRANSFER_TIME => 0x300000 + 17,
+ :CURLINFO_APPCONNECT_TIME => 0x300000 + 33,
+
}
AUTH_TYPES = {
:CURLAUTH_BASIC => 1,
@@ -104,6 +110,26 @@ def total_time_taken
get_info_double(INFO_VALUES[:CURLINFO_TOTAL_TIME])
end
+ def start_transfer_time
+ get_info_double(INFO_VALUES[:CURLINFO_STARTTRANSFER_TIME])
+ end
+
+ def app_connect_time
+ get_info_double(INFO_VALUES[:CURLINFO_APPCONNECT_TIME])
+ end
+
+ def pretransfer_time
+ get_info_double(INFO_VALUES[:CURLINFO_PRETRANSFER_TIME])
+ end
+
+ def connect_time
+ get_info_double(INFO_VALUES[:CURLINFO_CONNECT_TIME])
+ end
+
+ def name_lookup_time
+ get_info_double(INFO_VALUES[:CURLINFO_NAMELOOKUP_TIME])
+ end
+
def effective_url
get_info_string(INFO_VALUES[:CURLINFO_EFFECTIVE_URL])
end
View
17 lib/typhoeus/hydra.rb
@@ -212,12 +212,17 @@ def handle_request(request, response, live_request = true)
private :handle_request
def response_from_easy(easy, request)
- Response.new(:code => easy.response_code,
- :headers => easy.response_header,
- :body => easy.response_body,
- :time => easy.total_time_taken,
- :effective_url => easy.effective_url,
- :request => request)
+ Response.new(:code => easy.response_code,
+ :headers => easy.response_header,
+ :body => easy.response_body,
+ :time => easy.total_time_taken,
+ :start_transfer_time => easy.start_transfer_time,
+ :app_connect_time => easy.app_connect_time,
+ :pretransfer_time => easy.pretransfer_time,
+ :connect_time => easy.connect_time,
+ :name_lookup_time => easy.name_lookup_time,
+ :effective_url => easy.effective_url,
+ :request => request)
end
private :response_from_easy
end
View
10 lib/typhoeus/response.rb
@@ -4,7 +4,10 @@ class Response
attr_reader :code, :headers, :body, :time,
:requested_url, :requested_remote_method,
:requested_http_method, :start_time,
- :effective_url
+ :effective_url, :start_transfer_time,
+ :app_connect_time, :pretransfer_time,
+ :connect_time, :name_lookup_time
+
attr_writer :headers_hash
def initialize(params = {})
@@ -17,6 +20,11 @@ def initialize(params = {})
@requested_url = params[:requested_url]
@requested_http_method = params[:requested_http_method]
@start_time = params[:start_time]
+ @start_transfer_time = params[:start_transfer_time]
+ @app_connect_time = params[:app_connect_time]
+ @pretransfer_time = params[:pretransfer_time]
+ @connect_time = params[:connect_time]
+ @name_lookup_time = params[:name_lookup_time]
@request = params[:request]
@effective_url = params[:effective_url]
@mock = params[:mock] || false # default

0 comments on commit 7eb00d9

Please sign in to comment.
Something went wrong with that request. Please try again.