Class: Rreplay::Http
- Inherits:
-
Object
- Object
- Rreplay::Http
- Defined in:
- lib/rreplay/replay_runner.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #call(orig_request) ⇒ Object
-
#initialize(endpoint) ⇒ Http
constructor
A new instance of Http.
Constructor Details
#initialize(endpoint) ⇒ Http
Returns a new instance of Http.
123 124 125 |
# File 'lib/rreplay/replay_runner.rb', line 123 def initialize(endpoint) @endpoint = endpoint end |
Instance Method Details
#call(orig_request) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/rreplay/replay_runner.rb', line 127 def call(orig_request) uri = URI(::File.join(@endpoint, orig_request['path'], orig_request['query_strings'])) body = orig_request['body'] headers = orig_request['headers'] headers.merge!({ 'User-Agent': 'RreplayRunner' }) request_clazz = case orig_request['method'].upcase when 'GET' Net::HTTP::Get when 'POST' Net::HTTP::Post when 'PUT' Net::HTTP::Put when 'PATCH' Net::HTTP::Patch when 'DELETE' Net::HTTP::Delete else # ignore return end request = request_clazz.new(uri, headers).tap do |req| req.body = body end start_time = Time.now response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') { |http| http.request(request) } Result.new(response, (Time.now - start_time).to_s) end |