Class: EventMachine::WebMockHttpClient
- Inherits:
-
HttpClient
- Object
- HttpClient
- EventMachine::WebMockHttpClient
- Includes:
- HttpEncoding
- Defined in:
- lib/webmock/http_lib_adapters/em_http_request_adapter.rb
Instance Method Summary collapse
- #connection_completed ⇒ Object
- #get_response_cookie(name) ⇒ Object
- #request_signature ⇒ Object
- #send_request(head, body) ⇒ Object
- #setup(response, uri, error = nil) ⇒ Object
- #stubbed_webmock_response ⇒ Object
- #unbind(reason = nil) ⇒ Object
- #uri ⇒ Object
Instance Method Details
#connection_completed ⇒ Object
102 103 104 105 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 102 def connection_completed @state = :response_header send_request(request_signature.headers, request_signature.body) end |
#get_response_cookie(name) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 151 def (name) name = name.to_s = response_header. = [] if .is_a? String = .select { |c| c.start_with? name }.first and .split('=', 2)[1] end |
#request_signature ⇒ Object
139 140 141 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 139 def request_signature @request_signature ||= build_request_signature end |
#send_request(head, body) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 107 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_response ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 143 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
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 125 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 |
#uri ⇒ Object
86 87 88 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 86 def uri @req.uri end |