Module: WebMock::NetHTTPUtility
- Defined in:
- lib/webmock/http_lib_adapters/net_http.rb
Class Method Summary collapse
- .check_right_http_connection ⇒ Object
- .get_uri(net_http, path = nil) ⇒ Object
- .puts_warning_for_right_http_if_needed ⇒ Object
- .request_signature_from_request(net_http, request, body = nil) ⇒ Object
Class Method Details
.check_right_http_connection ⇒ Object
283 284 285 |
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 283 def self.check_right_http_connection @was_right_http_connection_loaded = defined?(RightHttpConnection) end |
.get_uri(net_http, path = nil) ⇒ Object
274 275 276 277 278 279 280 281 |
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 274 def self.get_uri(net_http, path = nil) protocol = net_http.use_ssl? ? "https" : "http" hostname = net_http.address hostname = "[#{hostname}]" if /\A\[.*\]\z/ !~ hostname && /:/ =~ hostname "#{protocol}://#{hostname}:#{net_http.port}#{path}" end |
.puts_warning_for_right_http_if_needed ⇒ Object
287 288 289 290 291 |
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 287 def self.puts_warning_for_right_http_if_needed if !@was_right_http_connection_loaded && defined?(RightHttpConnection) $stderr.puts "\nWarning: RightHttpConnection has to be required before WebMock is required !!!\n" end end |
.request_signature_from_request(net_http, request, body = nil) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 246 def self.request_signature_from_request(net_http, request, body = nil) path = request.path if path.respond_to?(:request_uri) #https://github.com/bblimke/webmock/issues/288 path = path.request_uri end path = WebMock::Util::URI.heuristic_parse(path).request_uri if path =~ /^http/ uri = get_uri(net_http, path) method = request.method.downcase.to_sym headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}] if request.body_stream body = request.body_stream.read request.body_stream = nil end if body != nil && body.respond_to?(:read) request.set_body_internal body.read else request.set_body_internal body end WebMock::RequestSignature.new(method, uri, body: request.body, headers: headers) end |