Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for Curl.head #148

Merged
merged 1 commit into from Apr 14, 2013
Merged

Bugfix for Curl.head #148

merged 1 commit into from Apr 14, 2013

Conversation

ruafozy
Copy link

@ruafozy ruafozy commented Mar 31, 2013

No description provided.

taf2 added a commit that referenced this pull request Apr 14, 2013
@taf2 taf2 merged commit e39c9f1 into taf2:master Apr 14, 2013
@deltheil
Copy link

deltheil commented May 5, 2013

I faced the same issue while I was answering a question on SO (that's why I omitted the Curl.head shortcut in my answer).

Behind the scenes, this patch is equivalent to:

curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "HEAD");

If we refer to libcurl documentation, we can see the recommended way to perform a HEAD request is as follow:

To switch to a proper HEAD use CURLOPT_NOBODY, [...].

Since this is precisely what http_head does, I would suggest tweaking this patch by modifying the self.http as follow:

def self.http(verb, url, post_body=nil, put_data=nil, &block)
  handle = Curl::Easy.new(url)
  handle.post_body = post_body if post_body
  handle.put_data = put_data if put_data
  yield handle if block_given?
  verb == :HEAD ? handle.http_head : handle.http(verb)
  handle
end

In other words, do an explicit http_head call when appropriate.

Feel free to let me know if you want me to submit a new pull request with this small tweak.

Note: on my own this behaves better since I've observed that curl could hang and raise an error (e.g with the request below) with this CURLOPT_CUSTOMREQUEST approach:

> h = Curl.head("http://www.google.com")
Curl::Err::PartialFileError: Curl::Err::PartialFileError

Reproduced on Mac OS X 10.6.8 with libcurl 7.19.7, the (old!) version shipped with the Mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants