Class: Crusher::HttpLoadGenerator

Inherits:
LoadGenerator show all
Defined in:
lib/crusher/http_load_generator.rb

Instance Method Summary collapse

Methods inherited from LoadGenerator

#act!, #log, #log_stats, #prepare, #stats_log_file

Constructor Details

#initialize(crush_session, options) ⇒ HttpLoadGenerator

Returns a new instance of HttpLoadGenerator.



6
7
8
9
# File 'lib/crusher/http_load_generator.rb', line 6

def initialize(crush_session, options)
  super(crush_session, options)
  @cookies = ::WebAgent::CookieManager.new 
end

Instance Method Details

#request(method, path, content = {}, custom_headers = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/crusher/http_load_generator.rb', line 11

def request(method, path, content = {}, custom_headers = {}, &block)

  uri = URI.parse(path)

  http_args = content.keys.map do |key| 
    content[key] ? "#{CGI.escape(key.to_s)}=#{CGI.escape(content[key].to_s)}" : nil
  end
  
  qs, content = if method == :get
    [((uri.query || '').split('&') + http_args.compact).join("&"), nil]
  else
    [uri.query, http_args.join("&")] 
  end

  options = {
    :verb => method,
    :host => uri.host,
    :port => uri.port,
    :request => uri.path,
    :query_string => qs,
    :content => content,
    :custom_headers => custom_headers,
    :contenttype => 'application/x-www-form-urlencoded',
    :cookie => @cookies.find(uri),
    :ssl => (uri.scheme == "https" ? true : false)
  }
  
  start_time = Time.now
  em_request(start_time, uri, block, options)

end