Class: EventMachine::WebMockHttpClient

Inherits:
HttpClient
  • Object
show all
Includes:
HttpEncoding
Defined in:
lib/webmock/http_lib_adapters/em_http_request_adapter.rb

Instance Method Summary collapse

Instance Method Details



146
147
148
149
150
151
152
153
154
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 146

def get_response_cookie(name)
  name = name.to_s

  raw_cookie = response_header.cookie
  raw_cookie = [raw_cookie] if raw_cookie.is_a? String

  cookie = raw_cookie.select { |c| c.start_with? name }.first
  cookie and cookie.split('=', 2)[1]
end

#request_signatureObject



134
135
136
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 134

def request_signature
  @request_signature ||= build_request_signature
end

#send_request(head, body) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 102

def send_request(head, body)
  WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)

  if stubbed_webmock_response
    WebMock::CallbackRegistry.invoke_callbacks({lib: :em_http_request}, request_signature, stubbed_webmock_response)
    @uri ||= nil
    EM.next_tick {
      setup(make_raw_response(stubbed_webmock_response), @uri,
            stubbed_webmock_response.should_timeout ? Errno::ETIMEDOUT : nil)
    }
    self
  elsif WebMock.net_connect_allowed?(request_signature.uri)
    super
  else
    raise WebMock::NetConnectNotAllowedError.new(request_signature)
  end
end

#setup(response, uri, error = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 90

def setup(response, uri, error = nil)
  @last_effective_url = @uri = uri
  if error
    on_error(error)
    @conn.drop_client
    fail(self)
  else
    @conn.receive_data(response)
    succeed(self)
  end
end

#stubbed_webmock_responseObject



138
139
140
141
142
143
144
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 138

def stubbed_webmock_response
  unless defined?(@stubbed_webmock_response)
    @stubbed_webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
  end

  @stubbed_webmock_response
end

#unbind(reason = nil) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 120

def unbind(reason = nil)
  if !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
    webmock_response = build_webmock_response
    WebMock::CallbackRegistry.invoke_callbacks(
      {lib: :em_http_request, real_request: true},
      request_signature,
      webmock_response)
  end
  @request_signature = nil
  remove_instance_variable(:@stubbed_webmock_response)

  super
end

#uriObject



86
87
88
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 86

def uri
  @req.uri
end