Skip to content

Commit

Permalink
httpclient response header receives request_method, request_uri, and …
Browse files Browse the repository at this point in the history
…request_query transferred from httpclient request header
  • Loading branch information
trlorenz committed Jun 20, 2014
1 parent 2a587b2 commit 50da9b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/webmock/http_lib_adapters/httpclient_adapter.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def do_get(req, proxy, conn, stream = false, &block)


if webmock_responses[request_signature] if webmock_responses[request_signature]
webmock_response = webmock_responses.delete(request_signature) webmock_response = webmock_responses.delete(request_signature)
response = build_httpclient_response(webmock_response, stream, &block) response = build_httpclient_response(webmock_response, stream, req.header, &block)
@request_filter.each do |filter| @request_filter.each do |filter|
filter.filter_response(req, response) filter.filter_response(req, response)
end end
Expand Down Expand Up @@ -89,9 +89,9 @@ def do_request_async(method, uri, query, body, extheader)
end end
end end


def build_httpclient_response(webmock_response, stream = false, &block) def build_httpclient_response(webmock_response, stream = false, req_header = nil, &block)
body = stream ? StringIO.new(webmock_response.body) : webmock_response.body body = stream ? StringIO.new(webmock_response.body) : webmock_response.body
response = HTTP::Message.new_response(body) response = HTTP::Message.new_response(body, req_header)
response.header.init_response(webmock_response.status[0]) response.header.init_response(webmock_response.status[0])
response.reason=webmock_response.status[1] response.reason=webmock_response.status[1]
webmock_response.headers.to_a.each { |name, value| response.header.set(name, value) } webmock_response.headers.to_a.each { |name, value| response.header.set(name, value) }
Expand Down
7 changes: 7 additions & 0 deletions spec/acceptance/httpclient/httpclient_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -152,4 +152,11 @@ def filter_response(request, response)


end end


context 'httpclient response header' do
it 'receives request_method, request_uri, and request_query from the request header' do
stub_request :get, 'www.example.com'
message = HTTPClient.new.get 'www.example.com'
message.header.request_uri.to_s.should == 'www.example.com'
end
end
end end

0 comments on commit 50da9b4

Please sign in to comment.