Permalink
Browse files

change HEAD to return headers instead of response body

  • Loading branch information...
1 parent 48a63f1 commit 36a7cc400bccc13b4027687af81b60679297130f @godfat committed Jul 10, 2012
Showing with 20 additions and 12 deletions.
  1. +4 −4 lib/rest-core/client.rb
  2. +16 −8 test/test_client.rb
View
@@ -107,7 +107,7 @@ def head path, query={}, opts={}, &cb
request(
{REQUEST_METHOD => :head ,
REQUEST_PATH => path ,
- REQUEST_QUERY => query }.merge(opts), &cb)
+ REQUEST_QUERY => query }.merge(opts), RESPONSE_HEADERS, &cb)
end
def options path, query={}, opts={}, &cb
@@ -141,13 +141,13 @@ def patch path, payload={}, query={}, opts={}, &cb
REQUEST_PAYLOAD => payload}.merge(opts), &cb)
end
- def request env, app=app
+ def request env, key=RESPONSE_BODY, app=app
if block_given?
request_full(env, app){ |response|
- yield(response[RESPONSE_BODY])
+ yield(response[key])
}
else
- request_full(env, app)[RESPONSE_BODY]
+ request_full(env, app)[key]
end
end
View
@@ -8,20 +8,28 @@
end
should 'do simple request' do
- [:get, :post, :delete, :put,
- :head, :patch, :options].each do |method|
- stub_request(method, 'http://localhost/').to_return(:body => '[]')
- RC::Simple.new.send(method, 'http://localhost/').should.eq '[]'
+ url = 'http://localhost/'
+ [:get, :post, :delete, :put, :patch, :options].each do |method|
+ stub_request(method, url).to_return(:body => '[]')
+ RC::Simple.new.send(method, url).should.eq '[]'
end
+
+ stub_request(:head, url).to_return(:headers => {'A' => 'B'})
+ RC::Simple.new.head(url).should.eq({'A' => 'B'})
end
should 'call the callback' do
- [:get, :post, :delete, :put,
- :head, :patch, :options].each do |method|
- stub_request(method, 'http://localhost/').to_return(:body => '123')
- (client = RC::Simple.new).send(method, 'http://localhost/'){ |res|
+ url = 'http://localhost/'
+ [:get, :post, :delete, :put, :patch, :options].each do |method|
+ stub_request(method, url).to_return(:body => '123')
+ (client = RC::Simple.new).send(method, url){ |res|
res.should.eq '123' }.should.eq client
end
+
+ stub_request(:head, url).to_return(:headers => {'A' => 'B'})
+ (client = RC::Simple.new).head(url){ |res|
+ res.should.eq({'A' => 'B'})
+ }.should.eq client
end
should 'have correct to_i' do

0 comments on commit 36a7cc4

Please sign in to comment.