mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
RestClient.head
This commit is contained in:
parent
b5ab20ad51
commit
109ad553dc
6 changed files with 23 additions and 4 deletions
|
@ -31,10 +31,14 @@ require File.dirname(__FILE__) + '/restclient/exceptions'
|
|||
# # DELETE
|
||||
# RestClient.delete 'http://example.com/resource'
|
||||
#
|
||||
# # retreive the response headers
|
||||
# # retreive the response http code and headers
|
||||
# res = RestClient.get 'http://example.com/some.jpg'
|
||||
# res.code # => 200
|
||||
# res.headers[:content_type] # => 'image/jpg'
|
||||
#
|
||||
# # HEAD
|
||||
# RestClient.head('http://example.com').headers
|
||||
#
|
||||
# To use with a proxy, just set RestClient.proxy to the proper http proxy:
|
||||
#
|
||||
# RestClient.proxy = "http://proxy.example.com/"
|
||||
|
@ -65,6 +69,10 @@ module RestClient
|
|||
Request.execute(:method => :delete, :url => url, :headers => headers)
|
||||
end
|
||||
|
||||
def self.head(url, headers={})
|
||||
Request.execute(:method => :head, :url => url, :headers => headers)
|
||||
end
|
||||
|
||||
class << self
|
||||
attr_accessor :proxy
|
||||
end
|
||||
|
|
|
@ -97,12 +97,15 @@ module RestClient
|
|||
net.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
net.read_timeout = @timeout if @timeout
|
||||
net.open_timeout = @open_timeout if @open_timeout
|
||||
|
||||
display_log request_log
|
||||
|
||||
net.start do |http|
|
||||
res = http.request(req, payload)
|
||||
display_log response_log(res)
|
||||
string = process_result(res)
|
||||
if string
|
||||
|
||||
if string or @method == :head
|
||||
Response.new(string, res)
|
||||
else
|
||||
nil
|
||||
|
|
|
@ -10,7 +10,7 @@ module RestClient
|
|||
|
||||
def initialize(string, net_http_res)
|
||||
@net_http_res = net_http_res
|
||||
super string
|
||||
super(string || "")
|
||||
end
|
||||
|
||||
# HTTP status code, always 200 since RestClient throws exceptions for
|
||||
|
|
|
@ -325,5 +325,4 @@ describe RestClient::Request do
|
|||
|
||||
@request.transmit(@uri, 'req', nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -38,4 +38,8 @@ describe RestClient::Response do
|
|||
it "can access the net http result directly" do
|
||||
@response.net_http_res.should == @net_http_res
|
||||
end
|
||||
|
||||
it "accepts nil strings and sets it to empty for the case of HEAD" do
|
||||
RestClient::Response.new(nil, @net_http_res).should == ""
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,11 @@ describe RestClient do
|
|||
RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
|
||||
RestClient.delete('http://some/resource')
|
||||
end
|
||||
|
||||
it "HEAD" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
|
||||
RestClient.head('http://some/resource')
|
||||
end
|
||||
end
|
||||
|
||||
describe "logging" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue