Class: PathTo::HTTPClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/path-to/http_client.rb

Overview

path-to’s default HTTPClient. Any Object (ours just happens to be a Class that includes HTTParty) that provides get, put, post and delete for a String path and optional additional parameters will do.

If you only need one such object, simply pass it in as a parameter when constructing your Application object. Override Path#http_client if you need more control than that.

Class Method Summary collapse

Class Method Details

.head(uri_string, headers = {}) ⇒ Object

HEAD request, returns some sort of NET::HTTPResponse

A bit ugly and out of place this, but HTTParty doesn’s support HEAD yet. (@jnunemaker@asplake there is a patch for head requests I need to pull in)

Raises:

  • (URI::InvalidURIError)


24
25
26
27
28
29
30
31
# File 'lib/path-to/http_client.rb', line 24

def self.head(uri_string, headers={})
  uri = URI.parse(uri_string)
  raise URI::InvalidURIError.new("#{uri_string.inspect} is not a valid http URI") unless uri.kind_of?(URI::HTTP) && uri.host

  Net::HTTP.new(uri.host, uri.port).start do |http|
    return http.request(Net::HTTP::Head.new(uri.request_uri, headers))
  end
end