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

.last_request_indexObject



50
51
52
# File 'lib/http_vanilli/net_http/override.rb', line 50

def last_request_index
  @last_request_index ||= -1
end

.next_request_indexObject



54
55
56
57
# File 'lib/http_vanilli/net_http/override.rb', line 54

def next_request_index
  @last_request_index ||= -1
  @last_request_index += 1
end

.socket_type_with_http_vanilliObject Also known as: socket_type



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

def socket_type_with_http_vanilli
  HttpVanilli::NetHttp::StubSocket
end

Instance Method Details

#connect_with_http_vanilliObject Also known as: connect



87
88
89
90
91
92
93
# File 'lib/http_vanilli/net_http/override.rb', line 87

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/http_vanilli/net_http/override.rb', line 60

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, self.class.next_request_index, &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