Class: Net::HTTP

Inherits:
Object show all
Defined in:
lib/http_vanilli/net_http/override.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.socket_type_with_http_vanilliObject Also known as: socket_type



43
44
45
# File 'lib/http_vanilli/net_http/override.rb', line 43

def socket_type_with_http_vanilli
  HttpVanilli::NetHttp::StubSocket
end

Instance Method Details

#connect_with_http_vanilliObject Also known as: connect



77
78
79
80
81
82
83
# File 'lib/http_vanilli/net_http/override.rb', line 77

def connect_with_http_vanilli
  unless @@alredy_checked_for_net_http_replacement_libs ||= false
    HttpVanilli::NetHttp.puts_warning_for_net_http_replacement_libs_if_needed
    @@alredy_checked_for_net_http_replacement_libs = true
  end
  nil
end

#request_with_http_vanilli(request, body = nil, &block) ⇒ Object Also known as: request



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/http_vanilli/net_http/override.rb', line 50

def request_with_http_vanilli(request, body = nil, &block)
  mapper = HttpVanilli.request_mapper

  request.set_body_internal body

  # Wrap Net::HTTPRequest & associated info in a HttpVanilli::Request
  vanilli_request = mapper.build_request(:net_http, self, request, &block)

  # The mapper can map the request. Do it.
  if mapper.map_request?(vanilli_request)
    @socket = Net::HTTP.socket_type.new
    mapper.map_request(vanilli_request)

  # otherwise, either allow the request to happen as normal,
  elsif HttpVanilli.allow_net_connect?
    connect_without_http_vanilli
    request_without_http_vanilli(request, body, &block)

  # or note the request as unmapped.
  else
    mapper.unmapped_request(vanilli_request)
  end
end