53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/web/ext/net_http.rb', line 53
def request_with_web(request, body = nil, &block)
connect
= {}
request.each do |key, value|
[key] = value
end
web = Web::Faker.new request.method.downcase.to_sym, request_uri_as_string(request), body,
if web.desired? && web_response = web.response_for
response = Net::HTTPResponse.send(:response_class, web_response.code.to_s).new('1.0', web_response.code.to_s, HTTP_STATUS_CODES[web_response.code])
web_response..each do |name, value|
if value.respond_to?(:each)
value.each { |val| response.add_field(name, val) }
else
response[name] = value
end
end
response.extend Web::ReadableHTTPResponse
response.instance_variable_set(:@body, web_response.body)
response.instance_variable_set(:@read, true)
yield response if block_given?
response.instance_variable_set(:@cached, true)
response
else
if web.desired?
response = request_without_web(request, body)
= {}
response.each do |key, value|
[key] = value
end
response.extend Web::ReadableHTTPResponse
web.record response.code.to_i, response.body,
yield response if block_given?
response
else
response = request_without_web(request, body, &block)
response.extend Web::HTTPResponse
response
end
end
end
|