class Object
Constants
- RSPEC_CONFIGURER
- RSPEC_NAMESPACE
Public Class Methods
new(args)
click to toggle source
Calls superclass method
# File lib/webmock/http_lib_adapters/excon_adapter.rb, line 147 def self.new(args) args.delete(:__construction_args) super(args).tap do |instance| instance.data[:__construction_args] = args end end
Public Instance Methods
auth_cred_from_headers(headers)
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 229 def auth_cred_from_headers(headers) headers.each do |k,v| next unless k =~ /[Aa]uthorization/ return v if v.is_a?(String) && v =~ /^Basic / v.each { |v| return v if v =~ /^Basic / } if v.is_a? Array end nil end
auth_cred_from_www_auth(req)
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 223 def auth_cred_from_www_auth(req) auth = www_auth.basic_auth auth.challenge(req.header.request_uri, nil) auth.get(req) if auth.scheme == 'Basic' end
build_request_signature(req, reuse_existing = false)
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 169 def build_request_signature(req, reuse_existing = false) uri = WebMock::Util::URI.heuristic_parse(req.header.request_uri.to_s) uri.query = WebMock::Util::QueryMapper.values_to_query(req.header.request_query, :notation => WebMock::Config.instance.query_values_notation) if req.header.request_query uri.port = req.header.request_uri.port uri = uri.omit(:userinfo) @request_filter.each do |filter| filter.filter_request(req) end headers = req.header.all.inject({}) do |hdrs, header| hdrs[header[0]] ||= [] hdrs[header[0]] << header[1] hdrs end headers = headers_from_session(uri).merge(headers) if auth_cred = auth_cred_from_www_auth(req) || auth_cred_from_headers(headers) remove_authorization_header headers uri.userinfo = userinfo_from_auth_cred auth_cred end signature = WebMock::RequestSignature.new( req.header.request_method.downcase.to_sym, uri.to_s, :body => req.http_body.dump, :headers => headers ) # reuse a previous identical signature object if we stored one for later use if reuse_existing && previous_signature = previous_signature_for(signature) return previous_signature end signature end
build_webmock_response(httpclient_response, body = nil)
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 142 def build_webmock_response(httpclient_response, body = nil) webmock_response = WebMock::Response.new webmock_response.status = [httpclient_response.status, httpclient_response.reason] webmock_response.headers = {}.tap do |hash| httpclient_response.header.all.each do |(key, value)| if hash.has_key?(key) hash[key] = Array(hash[key]) + [value] else hash[key] = value end end end if body webmock_response.body = body elsif httpclient_response.content.respond_to?(:read) webmock_response.body = httpclient_response.content.read body = HTTP::Message::Body.new body.init_response(StringIO.new(webmock_response.body)) httpclient_response.body = body else webmock_response.body = httpclient_response.content end webmock_response end
headers_from_session(uri)
click to toggle source
some of the headers sent by HTTPClient are derived from the client session
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 257 def headers_from_session(uri) session_headers = HTTP::Message::Headers.new @session_manager.send(:open, uri).send(:set_header, MessageMock.new(session_headers)) session_headers.all.inject({}) do |hdrs, header| hdrs[header[0]] = header[1] hdrs end end
previous_signature_for(signature)
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 248 def previous_signature_for(signature) return nil unless index = webmock_request_signatures.index(signature) webmock_request_signatures.delete_at(index) end
teardown_with_webmock()
click to toggle source
# File lib/webmock/minitest.rb, line 17 def teardown_with_webmock teardown_without_webmock WebMock.reset! end
userinfo_from_auth_cred(auth_cred)
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 206 def userinfo_from_auth_cred auth_cred userinfo = WebMock::Util::Headers.decode_userinfo_from_header(auth_cred) WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo) end
webmock_request_signatures()
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 244 def webmock_request_signatures @webmock_request_signatures ||= [] end
webmock_responses()
click to toggle source
# File lib/webmock/http_lib_adapters/httpclient_adapter.rb, line 238 def webmock_responses @webmock_responses ||= Hash.new do |hash, request_signature| hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature) end end