8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/supergood/vendors/net-http.rb', line 8
def self.patch
if !self.existing_patch?
block = lambda do |x|
alias original_request_method request
def request(original_request_payload, body = nil, &block)
http = self
url = Supergood::Utils.request_url(http, original_request_payload)
uri = URI.parse(url)
request = {
headers: Supergood::Utils.(original_request_payload),
method: original_request_payload.method,
body: original_request_payload.body,
url: url,
path: original_request_payload.path,
search: uri.query,
domain: Supergood::Utils.get_host_without_www(uri.host)
}
Supergood.intercept(request) do
original_response = original_request_method(original_request_payload, body, &block)
{
headers: Supergood::Utils.(original_response),
status: original_response.code,
statusText: original_response.message,
body: original_response.body,
original_response: original_response
}
end
end
end
if defined?(Net::HTTP)
Net::HTTP.class_eval(&block)
elsif defined?(::WebMock)
WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get("@webMockNetHTTP").class_eval(&block)
end
end
end
|