License:
BSD style: see license.txt
Version:
Initial release: April 2004
Outback release: December 2006
author:
Kris - original module
author:
h3r3tic - fixed a number of Post issues and
bugs in the 'params' construction
Redirection handling guided via
http:
//ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html
- class
HttpClient
;
- 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 client = new HttpClient (HttpClient.Get, "http://www.yahoo.com");
// make request
client.open ();
// check return status for validity
if (client.isResponseOK)
{
// extract content length
auto length = client.getResponseHeaders.getInt (HttpHeader.ContentLength, uint.max);
// display all returned headers
Stdout.put (client.getResponseHeaders);
// display remaining content
client.read (&sink, length);
}
else
Stderr.put (client.getResponse);
client.close ();
See modules HttpGet and HttpPost for simple wrappers instead.
- this(RequestMethod method, char[] url);
- 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.
- this(RequestMethod method, Uri uri);
- 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.
- HttpHeadersView
getResponseHeaders
();
- Get the current input headers, as returned by the host request.
- HttpHeaders
getRequestHeaders
();
- Gain access to the request headers. Use this to add whatever
headers are required for a request.
- HttpParams
getRequestParams
();
- 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.
- UriView
getUri
();
- Return the Uri associated with this client
- ResponseLine
getResponse
();
- Return the response-line for the latest request. This takes
the form of "version status reason" as defined in the HTTP
RFC.
- int
getStatus
();
- Return the HTTP status code set by the remote server
- bool
isResponseOK
();
- Return whether the response was OK or not
- void
addCookie
(Cookie cookie);
- Add a cookie to the outgoing headers
- void
close
();
- Close all resources used by a request. You must invoke this
between successive open() calls.
- void
reset
();
- Reset the client such that it is ready for a new request.
- void
setRequest
(RequestMethod method);
- Set the request method
- void
setVersion
(Version v);
- Set the request version
- void
enableRedirect
(bool yes);
- enable/disable the internal redirection suppport
- void
setTimeout
(float interval);
- set timeout period for read operation
- void
keepAlive
(bool yes);
- Control keepalive option
- void
encodeUri
(bool yes);
- Control Uri output encoding
- IBuffer
open
(IBuffer buffer = cast(IBuffer)null);
- 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.
- IBuffer
open
(void delegate(IBuffer) pump, IBuffer buffer = cast(IBuffer)null);
- 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.
- void
read
(void delegate(void[]) sink, long len = 9223372036854775807L);
- Read the content from the returning input stream, up to a
maximum length, and pass content to the given sink delegate
as it arrives.
Exits when length bytes have been processed, or an Eof is
seen on the stream.
- IBuffer
redirectPost
(void delegate(IBuffer) pump, IBuffer input, int status);
- Handle redirection of Post
Guidance for the default behaviour came from this page:
http:
//ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html
- bool
canRepost
(uint status);
- Handle user-notification of Post redirection. This should
be overridden appropriately.
Guidance for the default behaviour came from this page:
http:
//ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html
- protected SocketConduit
createSocket
();
- Overridable socket factory, for use with HTTPS and so on
|