Class Client
In: lib/facets/more/httpaccess.rb
Parent: Object

DESCRIPTION

  HTTPAccess::Client -- Client to retrieve web resources via HTTP.

How to create your client.

  1. Create simple client.
    clnt = HTTPAccess::Client.new

  2. Accessing resources through HTTP proxy.
    clnt = HTTPAccess::Client.new("http://myproxy:8080")

  3. Set User-Agent and From in HTTP request header.(nil means "No proxy")
    clnt = HTTPAccess::Client.new(nil, "MyAgent", "nahi@keynauts.com")

How to retrieve web resources.

  1. Get content of specified URL.
    puts clnt.get_content("http://www.ruby-lang.org/en/")

  2. Do HEAD request.
    res = clnt.head(uri)

  3. Do GET request with query.
    res = clnt.get(uri)

  4. Do POST request.
    res = clnt.post(uri)
    res = clnt.get|post|head(uri, proxy)

Methods

Constants

NO_PROXY_HOSTS = ['localhost']

Attributes

agent_name  [R] 
cookie_manager  [RW] 
from  [R] 
ssl_config  [R] 
test_loopback_response  [R] 

Public Class methods

SYNOPSIS

  Client.new(proxy = nil, agent_name = nil, from = nil)

ARGS

  proxy             A String of HTTP proxy URL. ex. "http://proxy:8080".
  agent_name        A String for "User-Agent" HTTP request header.
  from              A String for "From" HTTP request header.

DESCRIPTION

  Create an instance.
  SSLConfig cannot be re-initialized.  Create new client.

Public Instance methods

SYNOPSIS

  Client#get_content(uri, query = nil, extheader = {}, &block = nil)

ARGS

  uri       an_URI or a_string of uri to connect.
  query     a_hash or an_array of query part.  e.g. { "a" => "b" }.
            Give an array to pass multiple value like
            [["a" => "b"], ["a" => "c"]].
  extheader
            a_hash of extra headers like { "SOAPAction" => "urn:foo" }.
  &block    Give a block to get chunked message-body of response like
            get_content(uri) { |chunked_body| ... }
            Size of each chunk may not be the same.

DESCRIPTION

  Get a_sring of message-body of response.

Management interface.

if your ruby is older than 2005-09-06, do not set socket_sync = false to avoid an SSL socket blocking bug in openssl/buffering.rb.

[Validate]