HTTP

Tracking progress:

import std.net.curl, std.stdio;

auto http = HTTP();
http.method = HTTP.Method.get;
http.url = "http://upload.wikimedia.org/wikipedia/commons/" ~
           "5/53/Wikipedia-logo-en-big.png";
http.onReceive = (ubyte[] data) { return data.length; };
http.onProgress = (size_t dltotal, size_t dlnow,
                   size_t ultotal, size_t ulnow)
{
    writeln("Progress ", dltotal, ", ", dlnow, ", ", ultotal, ", ", ulnow);
    return 0;
};
http.perform();
struct HTTP {}

Members

Aliases

AuthMethod
alias AuthMethod = CurlAuth

Authentication method equal to etc.c.curl.CurlAuth

CurlProxy
alias CurlProxy = etc.c.curl.CurlProxy

Type of proxy

TimeCond
alias TimeCond = CurlTimeCond

Time condition enumeration as an alias of etc.c.curl.CurlTimeCond

requestAbort
alias requestAbort = CurlReadFunc.abort

Value to return from onSend delegate in order to abort a request

requestPause
alias requestPause = CurlReadFunc.pause

Value to return from onSend/onReceive delegates in order to pause a request

Enums

Method
enum Method

<a name="HTTP.Method"/>The standard HTTP methods : _RFC2616 Section 5.1.1

Functions

addRequestHeader
void addRequestHeader(const(char)[] name, const(char)[] value)

Add a header e.g. "X-CustomField: Something is fishy".

clearAllCookies
void clearAllCookies()

Clear all cookies.

clearRequestHeaders
void clearRequestHeaders()

Clear all outgoing headers.

clearSessionCookies
void clearSessionCookies()

Clear session cookies.

dup
HTTP dup()
flushCookieJar
void flushCookieJar()

Flush cookie jar to disk.

getTiming
CurlCode getTiming(CurlInfo timing, double val)

Get various timings defined in etc.c.curl.CurlInfo. The value is usable only if the return value is equal to etc.c.curl.CurlError.ok.

perform
CurlCode perform(ThrowOnError throwOnError)

Perform a http request.

setAuthentication
void setAuthentication(const(char)[] username, const(char)[] password, const(char)[] domain)

Set the user name, password and optionally domain for authentication purposes.

setCookie
void setCookie(const(char)[] cookie)

Set the active cookie string e.g. "name1=value1;name2=value2"

setCookieJar
void setCookieJar(const(char)[] path)

Set a file path to where a cookie jar should be read/stored.

setPostData
void setPostData(const(void)[] data, string contentType)

Specify data to post when not using the onSend callback, with user-specified Content-Type.

setProxyAuthentication
void setProxyAuthentication(const(char)[] username, const(char)[] password)

Set the user name and password for proxy authentication.

setTimeCondition
void setTimeCondition(HTTP.TimeCond cond, SysTime timestamp)

Set time condition on the request.

setUserAgent
void setUserAgent(const(char)[] userAgent)

Set the value of the user agent request header field.

shutdown
void shutdown()

Stop and invalidate this instance.

Properties

authenticationMethod
AuthMethod authenticationMethod [@property setter]

Authentication method as specified in AuthMethod.

caInfo
const(char)[] caInfo [@property setter]

Set the CA certificate bundle file to use for SSL peer verification

connectTimeout
Duration connectTimeout [@property setter]

Set timeout for connecting.

contentLength
ulong contentLength [@property setter]

The content length in bytes when using request that has content e.g. POST/PUT and not using chunked transfer. Is set as the "Content-Length" header. Set to ulong.max to reset to chunked transfer.

dataTimeout
Duration dataTimeout [@property setter]

Set timeout for activity on connection.

dnsTimeout
Duration dnsTimeout [@property setter]

DNS lookup timeout.

isStopped
bool isStopped [@property getter]

True if the instance is stopped. A stopped instance is not usable.

localPort
ushort localPort [@property setter]

Set the local outgoing port to use.

localPortRange
ushort localPortRange [@property setter]

Set the local outgoing port range to use. This can be used together with the localPort property.

maxRedirects
uint maxRedirects [@property setter]

Set max allowed redirections using the location header. uint.max for infinite.

method
Method method [@property setter]
Method method [@property getter]

HTTP method used.

netInterface
const(char)[] netInterface [@property setter]
const(ubyte)[4] netInterface [@property setter]
InternetAddress netInterface [@property setter]

The network interface to use in form of the the IP of the interface.

onProgress
int delegate(size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) onProgress [@property setter]

Register an event handler that gets called to inform of upload/download progress.

onReceive
size_t delegate(ubyte[]) onReceive [@property setter]

The event handler that receives incoming data. Be sure to copy the incoming ubyte[] since it is not guaranteed to be valid after the callback returns.

onReceiveHeader
void delegate(in char[] key, in char[] value) onReceiveHeader [@property setter]

Set the event handler that receives incoming headers.

onReceiveStatusLine
void delegate(StatusLine) onReceiveStatusLine [@property setter]

Callback for each received StatusLine.

onSend
size_t delegate(void[]) onSend [@property setter]

The event handler that gets called when data is needed for sending. The length of the void[] specifies the maximum number of bytes that can be sent.

operationTimeout
Duration operationTimeout [@property setter]

Set maximum time an operation is allowed to take. This includes dns resolution, connecting, data transfer, etc.

postData
const(void)[] postData [@property setter]

Specifying data to post when not using the onSend callback.

postData
const(char)[] postData [@property setter]

Specifying data to post when not using the onSend callback.

proxy
const(char)[] proxy [@property setter]

Proxy See: _proxy

proxyPort
ushort proxyPort [@property setter]

Proxy port See: _proxy_port

proxyType
CurlProxy proxyType [@property setter]

Proxy type See: _proxy_type

responseHeaders
string[string] responseHeaders [@property getter]

The headers read from a successful response.

statusLine
StatusLine statusLine [@property getter]

HTTP status line of last response. One call to perform may result in several requests because of redirection.

tcpNoDelay
bool tcpNoDelay [@property setter]

Set the tcp no-delay socket option on or off. See: nodelay

url
const(char)[] url [@property setter]

The URL to specify the location of the resource.

verbose
bool verbose [@property setter]

Set verbose. This will print request information to stderr.

Static functions

defaultUserAgent
string defaultUserAgent()

The default "User-Agent" value send with a request. It has the form "Phobos-std.net.curl/PHOBOS_VERSION (libcurl/CURL_VERSION)"

opCall
HTTP opCall(const(char)[] url)

Constructor taking the url as parameter.

opCall
HTTP opCall()

Structs

StatusLine
struct StatusLine

HTTP status line ie. the first line returned in an HTTP response.

Mixed In Members

From mixin Protocol

requestPause
alias requestPause = CurlReadFunc.pause

Value to return from onSend/onReceive delegates in order to pause a request

requestAbort
alias requestAbort = CurlReadFunc.abort

Value to return from onSend delegate in order to abort a request

handle
Curl handle [@property getter]

The curl handle used by this connection.

isStopped
bool isStopped [@property getter]

True if the instance is stopped. A stopped instance is not usable.

shutdown
void shutdown()

Stop and invalidate this instance.

verbose
bool verbose [@property setter]

Set verbose. This will print request information to stderr.

dataTimeout
Duration dataTimeout [@property setter]

Set timeout for activity on connection.

operationTimeout
Duration operationTimeout [@property setter]

Set maximum time an operation is allowed to take. This includes dns resolution, connecting, data transfer, etc.

connectTimeout
Duration connectTimeout [@property setter]

Set timeout for connecting.

proxy
const(char)[] proxy [@property setter]

Proxy See: _proxy

proxyPort
ushort proxyPort [@property setter]

Proxy port See: _proxy_port

CurlProxy
alias CurlProxy = RawCurlProxy

Type of proxy

proxyType
CurlProxy proxyType [@property setter]

Proxy type See: _proxy_type

dnsTimeout
Duration dnsTimeout [@property setter]

DNS lookup timeout.

netInterface
const(char)[] netInterface [@property setter]
const(ubyte)[4] netInterface [@property setter]
InternetAddress netInterface [@property setter]

The network interface to use in form of the the IP of the interface.

localPort
ushort localPort [@property setter]

Set the local outgoing port to use.

setNoProxy
void setNoProxy(string hosts)

Set the no proxy flag for the specified host names.

localPortRange
ushort localPortRange [@property setter]

Set the local outgoing port range to use. This can be used together with the localPort property.

tcpNoDelay
bool tcpNoDelay [@property setter]

Set the tcp no-delay socket option on or off. See: nodelay

verifyPeer
bool verifyPeer [@property setter]

Sets whether SSL peer certificates should be verified. See: verifypeer

verifyHost
bool verifyHost [@property setter]

Sets whether the host within an SSL certificate should be verified. See: verifypeer

setAuthentication
void setAuthentication(const(char)[] username, const(char)[] password, const(char)[] domain)

Set the user name, password and optionally domain for authentication purposes.

setProxyAuthentication
void setProxyAuthentication(const(char)[] username, const(char)[] password)

Set the user name and password for proxy authentication.

onSend
size_t delegate(void[]) onSend [@property setter]

The event handler that gets called when data is needed for sending. The length of the void[] specifies the maximum number of bytes that can be sent.

onReceive
size_t delegate(ubyte[]) onReceive [@property setter]

The event handler that receives incoming data. Be sure to copy the incoming ubyte[] since it is not guaranteed to be valid after the callback returns.

onProgress
int delegate(size_t dlTotal, size_t dlNow, size_t ulTotal, size_t ulNow) onProgress [@property setter]

The event handler that gets called to inform of upload/download progress.

See Also

Meta

Suggestion Box / Bug Report