Top Level Namespace
Defined Under Namespace
Modules: Curl, EventMachine, Net, Test, WebMock
Classes: StringIO, StubSocket, WebMockHTTPClient
Constant Summary
- RSPEC_NAMESPACE =
Spec
- RSPEC_CONFIGURER =
Spec::Runner
Instance Method Summary
(collapse)
Instance Method Details
- (Object) build_request_signature(req, reuse_existing = false)
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/webmock/http_lib_adapters/httpclient_adapter.rb', line 133
def build_request_signature(req, reuse_existing = false)
uri = WebMock::Util::URI.heuristic_parse(req..request_uri.to_s)
uri.query = WebMock::Util::QueryMapper.values_to_query(req..request_query) if req..request_query
uri.port = req..request_uri.port
uri = uri.omit(:userinfo)
auth = www_auth.basic_auth
auth.challenge(req..request_uri, nil)
@request_filter.each do |filter|
filter.filter_request(req)
end
= req..all.inject({}) do |hdrs, |
hdrs[[0]] ||= []
hdrs[[0]] << [1]
hdrs
end
if (auth_cred = auth.get(req)) && auth.scheme == 'Basic'
userinfo = WebMock::Util::Headers.(auth_cred)
userinfo = WebMock::Util::URI.encode_unsafe_chars_in_userinfo(userinfo)
.reject! {|k,v| k =~ /[Aa]uthorization/ && v =~ /^Basic / } uri.userinfo = userinfo
end
signature = WebMock::RequestSignature.new(
req..request_method.downcase.to_sym,
uri.to_s,
:body => req.content,
:headers =>
)
if reuse_existing && previous_signature = previous_signature_for(signature)
return previous_signature
end
signature
end
|
- (Object) build_webmock_response(httpclient_response)
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/webmock/http_lib_adapters/httpclient_adapter.rb', line 108
def build_webmock_response(httpclient_response)
webmock_response = WebMock::Response.new
webmock_response.status = [httpclient_response.status, httpclient_response.reason]
webmock_response. = {}.tap do |hash|
httpclient_response..all.each do |(key, value)|
if hash.has_key?(key)
hash[key] = Array(hash[key]) + [value]
else
hash[key] = value
end
end
end
if 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
|
- (Object) previous_signature_for(signature)
184
185
186
187
|
# File 'lib/webmock/http_lib_adapters/httpclient_adapter.rb', line 184
def previous_signature_for(signature)
return nil unless index = webmock_request_signatures.index(signature)
webmock_request_signatures.delete_at(index)
end
|
- (Object) webmock_request_signatures
180
181
182
|
# File 'lib/webmock/http_lib_adapters/httpclient_adapter.rb', line 180
def webmock_request_signatures
@webmock_request_signatures ||= []
end
|
- (Object) webmock_responses
174
175
176
177
178
|
# File 'lib/webmock/http_lib_adapters/httpclient_adapter.rb', line 174
def webmock_responses
@webmock_responses ||= Hash.new do |hash, request_signature|
hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
end
end
|