Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

HttpClient Class Reference

List of all members.

Public Member Functions

 this (RequestMethod method, char[] url)
 this (RequestMethod method, MutableUri uri)
HttpHeaders getResponseHeaders ()
HttpMutableHeaders getRequestHeaders ()
HttpMutableParams getRequestParams ()
Uri getUri ()
ResponseLine getResponse ()
int getStatus ()
bool isResponseOK ()
void addCookie (Cookie cookie)
void close ()
void reset ()
IBuffer open (IWritable pump)
IBuffer open (uint timeout=DefaultReadTimeout)
IBuffer open (uint timeout, IWritable pump)

Static Public Attributes

static const RequestMethod Get = {"GET"}

Protected Member Functions

SocketConduit createSocket ()

Private Member Functions

IBuffer open (uint timeout, IWritable pump, RequestMethod method)
void read (void(*sink)(char[]), long length=long.max)
IBuffer redirectPost (uint timeout, IWritable pump, int status)
bool canRepost (uint status)

Private Attributes

MutableUri uri
Buffer input
Buffer output
SocketConduit socket
RequestMethod method
InternetAddress address
HttpMutableParams paramsOut
HttpHeaders headersIn
HttpMutableHeaders headersOut
HttpMutableCookies cookiesOut
ResponseLine responseLine

Static Private Attributes

static uint DefaultReadTimeout = System.Interval.Second * 3
static const char[] DefaultHttpVersion = "HTTP/1.0"

Classes

struct  RequestMethod

Detailed Description

Supports the basic needs of a client making requests of an HTTP server. The following is an example of how this might be used:

        // callback for client reader
        void sink (char[] content)
        {
                Stdout.put (content);
        }

        // create client for a GET request
        auto HttpClient client = new HttpClient (HttpClient.Get, "http://www.yahoo.com");

        // make request
        client.open ();

        // check return status for validity
        if (client.isResponseOK)
           {
           // extract content length
           int length = client.getResponseHeaders.getInt (HttpHeader.ContentLength, int.max);
        
           // display all returned headers
           Stdout.put (client.getResponseHeaders);
        
           // display remaining content
           client.read (&sink, length);
           }
        else
           Stderr.put (client.getResponse);

        client.close ();

Definition at line 100 of file HttpClient.d.


Member Function Documentation

this RequestMethod  method,
char[]  url
[inline]
 

Create a client for the given URL. The argument should be fully qualified with an "http:" or "https:" scheme, or an explicit port should be provided.

Definition at line 145 of file HttpClient.d.

References method.

this RequestMethod  method,
MutableUri  uri
[inline]
 

Create a client with the provided Uri instance. The Uri should be fully qualified with an "http:" or "https:" scheme, or an explicit port should be provided.

Definition at line 158 of file HttpClient.d.

References address, cookiesOut, Uri::getHost(), Uri::getValidPort(), headersIn, headersOut, HttpHeaders, method, paramsOut, responseLine, and uri.

HttpHeaders getResponseHeaders  )  [inline]
 

Get the current input headers, as returned by the host request.

Definition at line 180 of file HttpClient.d.

References headersIn.

HttpMutableHeaders getRequestHeaders  )  [inline]
 

Gain access to the request headers. Use this to add whatever headers are required for a request.

Definition at line 192 of file HttpClient.d.

References headersOut.

HttpMutableParams getRequestParams  )  [inline]
 

Gain access to the request parameters. Use this to add x=y style parameters to the request. These will be appended to the request assuming the original Uri does not contain any of its own.

Definition at line 206 of file HttpClient.d.

References paramsOut.

Uri getUri  )  [inline]
 

Return the Uri associated with this client

Definition at line 217 of file HttpClient.d.

References uri.

ResponseLine getResponse  )  [inline]
 

Return the response-line for the latest request. This takes the form of "version status reason" as defined in the HTTP RFC.

Definition at line 230 of file HttpClient.d.

References responseLine.

int getStatus  )  [inline]
 

Return the HTTP status code set by the remote server

Definition at line 241 of file HttpClient.d.

References ResponseLine::getStatus(), and responseLine.

Referenced by isResponseOK().

bool isResponseOK  )  [inline]
 

Return whether the response was OK or not

Definition at line 252 of file HttpClient.d.

References getStatus().

void addCookie Cookie  cookie  )  [inline]
 

Add a cookie to the outgoing headers

Definition at line 263 of file HttpClient.d.

References HttpMutableCookies::add(), and cookiesOut.

void close  )  [inline]
 

Close all resources used by a request. You must invoke this between successive open() calls.

Definition at line 275 of file HttpClient.d.

References SocketConduit::close(), Socket::shutdown(), and socket.

void reset  )  [inline]
 

Reset the client such that it is ready for a new request.

Definition at line 291 of file HttpClient.d.

References headersIn, headersOut, paramsOut, and HttpTokens::reset().

SocketConduit createSocket  )  [inline, protected]
 

Overridable method to create a Socket. You may find a need to override this for some purpose; perhaps to add input or output filters.

Definition at line 306 of file HttpClient.d.

References SocketConduit.

Referenced by open().

IBuffer open IWritable  pump  )  [inline]
 

Make a request for the resource specified via the constructor, using a callback for pumping additional data to the host. This defaults to a three-second timeout period. The return value represents the input buffer, from which all returned headers and content may be accessed.

Definition at line 321 of file HttpClient.d.

References DefaultReadTimeout.

Referenced by open(), and redirectPost().

IBuffer open uint  timeout = DefaultReadTimeout  )  [inline]
 

Make a request for the resource specified via the constructor, using the specified timeout period (in milli-seconds).The return value represents the input buffer, from which all returned headers and content may be accessed.

Definition at line 335 of file HttpClient.d.

References open().

IBuffer open uint  timeout,
IWritable  pump
[inline]
 

Make a request for the resource specified via the constructor using the specified timeout period (in micro-seconds), and a user-defined callback for pumping additional data to the host. The callback would be used when uploading data during a 'put' operation (or equivalent). The return value represents the input buffer, from which all returned headers and content may be accessed.

Definition at line 352 of file HttpClient.d.

References method, and open().

IBuffer open uint  timeout,
IWritable  pump,
RequestMethod  method
[inline, private]
 

Make a request for the resource specified via the constructor using the specified timeout period (in micro-seconds), and a user-defined callback for pumping additional data to the host. The callback would be used when uploading data during a 'put' operation (or equivalent). The return value represents the input buffer, from which all returned headers and content may be accessed.

Definition at line 369 of file HttpClient.d.

References HttpMutableHeaders::add(), address, Buffer, SocketConduit::close(), Socket::connect(), createSocket(), DefaultHttpVersion, DisplayWriter, ResponseLine::error(), MutableUri::extendQuery(), IWriter::flush(), Get, HttpHeaders::get(), Uri::getHost(), Uri::getPath(), ResponseLine::getStatus(), Head, headersIn, headersOut, input, HttpClient::RequestMethod::name, CompositeToken::next(), open(), output, paramsOut, MutableUri::parse(), ResponseLine::parse(), Post, Buffer::readable(), redirectPost(), HttpTokens::reset(), responseLine, Socket::setTimeout(), socket, uri, and IWritable::write().

void read void(*)(char[])  sink,
long  length = long.max
[inline, private]
 

Definition at line 461 of file HttpClient.d.

References Buffer::clear(), Buffer::fill(), input, Buffer::readable(), socket, and Buffer::toString().

IBuffer redirectPost uint  timeout,
IWritable  pump,
int  status
[inline, private]
 

Handle redirection of Post

Guidance for this default behaviour came from this page: http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html

Definition at line 479 of file HttpClient.d.

References canRepost(), ResponseLine::error(), Get, method, open(), and responseLine.

Referenced by open().

bool canRepost uint  status  )  [inline, private]
 

Handle user-notification of Post redirection. This should be overridden appropriately.

Guidance for this default behaviour came from this page: http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html

Definition at line 507 of file HttpClient.d.

Referenced by redirectPost().


Member Data Documentation

MutableUri uri [private]
 

Definition at line 109 of file HttpClient.d.

Referenced by getUri(), open(), and this().

Buffer input [private]
 

Definition at line 110 of file HttpClient.d.

Referenced by open(), and read().

Buffer output [private]
 

Definition at line 110 of file HttpClient.d.

Referenced by open().

SocketConduit socket [private]
 

Definition at line 112 of file HttpClient.d.

Referenced by close(), open(), and read().

RequestMethod method [private]
 

Definition at line 113 of file HttpClient.d.

Referenced by open(), redirectPost(), and this().

InternetAddress address [private]
 

Definition at line 114 of file HttpClient.d.

Referenced by open(), and this().

HttpMutableParams paramsOut [private]
 

Definition at line 115 of file HttpClient.d.

Referenced by getRequestParams(), open(), reset(), and this().

HttpHeaders headersIn [private]
 

Definition at line 116 of file HttpClient.d.

Referenced by getResponseHeaders(), open(), reset(), and this().

HttpMutableHeaders headersOut [private]
 

Definition at line 117 of file HttpClient.d.

Referenced by getRequestHeaders(), open(), reset(), and this().

HttpMutableCookies cookiesOut [private]
 

Definition at line 118 of file HttpClient.d.

Referenced by addCookie(), and this().

ResponseLine responseLine [private]
 

Definition at line 119 of file HttpClient.d.

Referenced by getResponse(), getStatus(), open(), redirectPost(), and this().

uint DefaultReadTimeout = System.Interval.Second * 3 [static, private]
 

Definition at line 122 of file HttpClient.d.

Referenced by open().

const char [] DefaultHttpVersion = "HTTP/1.0" [static, private]
 

Definition at line 125 of file HttpClient.d.

Referenced by open().

const RequestMethod Get = {"GET"} [static]
 

Definition at line 128 of file HttpClient.d.

Referenced by open(), and redirectPost().

Put = {"PUT"} []
 

Definition at line 129 of file HttpClient.d.

Head = {"HEAD"} []
 

Definition at line 130 of file HttpClient.d.

Referenced by open().

Post = {"POST"} []
 

Definition at line 131 of file HttpClient.d.

Referenced by open().

Trace = {"TRACE"} []
 

Definition at line 132 of file HttpClient.d.

Delete = {"DELETE"} []
 

Definition at line 133 of file HttpClient.d.

Options = {"OPTIONS"} []
 

Definition at line 134 of file HttpClient.d.

Connect = {"CONNECT"} []
 

Definition at line 135 of file HttpClient.d.


The documentation for this class was generated from the following file:
Generated on Sat Dec 24 17:28:39 2005 for Mango by  doxygen 1.4.0