# File lib/webmock/http_lib_adapters/em_http_request.rb, line 28 28: def send_request_with_webmock(&block) 29: request_signature = build_request_signature 30: 31: WebMock::RequestRegistry.instance.requested_signatures.put(request_signature) 32: 33: if WebMock.registered_request?(request_signature) 34: webmock_response = WebMock.response_for_request(request_signature) 35: WebMock::CallbackRegistry.invoke_callbacks( 36: {:lib => :em_http_request}, request_signature, webmock_response) 37: client = WebMockFakeHttpClient.new(nil) 38: client.on_error("WebMock timeout error") if webmock_response.should_timeout 39: client.setup(make_raw_response(webmock_response), @uri, 40: webmock_response.should_timeout ? "WebMock timeout error" : nil) 41: client 42: elsif WebMock.net_connect_allowed?(request_signature.uri) 43: http = send_request_without_webmock(&block) 44: http.callback { 45: if WebMock::CallbackRegistry.any_callbacks? 46: webmock_response = build_webmock_response(http) 47: WebMock::CallbackRegistry.invoke_callbacks( 48: {:lib => :em_http_request, :real_request => true}, request_signature, 49: webmock_response) 50: end 51: } 52: http 53: else 54: raise WebMock::NetConnectNotAllowedError.new(request_signature) 55: end 56: end
# File lib/webmock/http_lib_adapters/em_http_request.rb, line 72 72: def build_request_signature 73: if @req 74: options = @req.options 75: method = @req.method 76: uri = @req.uri 77: else 78: options = @options 79: method = @method 80: uri = @uri 81: end 82: 83: if options[:authorization] || options['authorization'] 84: auth = (options[:authorization] || options['authorization']) 85: userinfo = auth.join(':') 86: userinfo = WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo) 87: options.reject! {|k,v| k.to_s == 'authorization' } #we added it to url userinfo 88: uri.userinfo = userinfo 89: end 90: 91: uri.query_values = (uri.query_values || {}).merge(options[:query]) if options[:query] 92: 93: WebMock::RequestSignature.new( 94: method.downcase.to_sym, 95: uri.to_s, 96: :body => (options[:body] || options['body']), 97: :headers => (options[:head] || options['head']) 98: ) 99: end
# File lib/webmock/http_lib_adapters/em_http_request.rb, line 64 64: def build_webmock_response(http) 65: webmock_response = WebMock::Response.new 66: webmock_response.status = [http.response_header.status, http.response_header.http_reason] 67: webmock_response.headers = http.response_header 68: webmock_response.body = http.response 69: webmock_response 70: end
# File lib/webmock/http_lib_adapters/em_http_request.rb, line 102 102: def make_raw_response(response) 103: response.raise_error_if_any 104: 105: status, headers, body = response.status, response.headers, response.body 106: 107: response_string = [] 108: response_string << "HTTP/1.1 #{status[0]} #{status[1]}" 109: 110: headers.each do |header, value| 111: value = value.join(", ") if value.is_a?(Array) 112: response_string << "#{header}: #{value}" 113: end if headers 114: 115: response_string << "" << body 116: response_string.join("\n") 117: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.