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
106 107 108 109 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 106 def connection_completed @state = :response_header send_request(*headers_and_body_processed_by_middleware) end |
#get_response_cookie(name) ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 155 def (name) name = name.to_s = response_header. = [] if .is_a? String = .detect { |c| c.start_with? name } and .split('=', 2)[1] end |
#request_signature ⇒ Object
143 144 145 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 143 def request_signature @request_signature ||= build_request_signature end |
#send_request(head, body) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 111 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
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 94 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
147 148 149 150 151 152 153 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 147 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
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 129 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
90 91 92 |
# File 'lib/webmock/http_lib_adapters/em_http_request_adapter.rb', line 90 def uri @req.uri end |