View source code Display the source code in std/net/curl.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Struct std.net.curl.HTTP

HTTP client functionality.

Properties

Name Type Description
authenticationMethod [set] CurlAuth Authentication method as specified in AuthMethod.
caInfo [set] const(char)[] Set the CA certificate bundle file to use for SSL peer verification
connectTimeout [set] Duration Set timeout for connecting.
contentLength [set] ulong 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 [set] Duration Set timeout for activity on connection.
defaultUserAgent [get] string The default "User-Agent" value send with a request. It has the form "Phobos-std.net.curl/PHOBOS_VERSION (libcurl/CURL_VERSION)"
dnsTimeout [set] Duration DNS lookup timeout.
isStopped [get] bool True if the instance is stopped. A stopped instance is not usable.
localPort [set] ushort Set the local outgoing port to use.
localPortRange [set] ushort Set the local outgoing port range to use. This can be used together with the localPort property.
maxRedirects [set] uint Set max allowed redirections using the location header. uint.max for infinite.
method [get, set] HTTP.Method HTTP method used.
netInterface [set] const(char)[] The network interface to use in form of the the IP of the interface.
onProgress [set] int delegate(ulong, ulong, ulong, ulong) Register an event handler that gets called to inform of upload/download progress.
onReceive [set] ulong delegate(ubyte[]) 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 [set] void delegate(const(char[]), const(char[])) Set the event handler that receives incoming headers.
onReceiveStatusLine [set] void delegate(HTTP.StatusLine) Callback for each received StatusLine.
onSend [set] ulong delegate(void[]) 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 [set] Duration Set maximum time an operation is allowed to take. This includes dns resolution, connecting, data transfer, etc.
postData [set] const(void)[] Specifying data to post when not using the onSend callback.
postData [set] const(char)[] Specifying data to post when not using the onSend callback.
proxy [set] const(char)[] Proxy
proxyPort [set] ushort Proxy port
proxyType [set] CurlProxy Proxy type
responseHeaders [get] string[string] The headers read from a successful response.
statusLine [get] HTTP.StatusLine HTTP status line of last response. One call to perform may result in several requests because of redirection.
tcpNoDelay [set] bool Set the tcp no-delay socket option on or off.
url [set] const(char)[] The URL to specify the location of the resource.
verbose [set] bool Set verbose. This will print request information to stderr.

Methods

Name Description
addRequestHeader Add a header e.g. "X-CustomField: Something is fishy".
clearAllCookies Clear all cookies.
clearRequestHeaders Clear all outgoing headers.
clearSessionCookies Clear session cookies.
flushCookieJar Flush cookie jar to disk.
opCall Constructor taking the url as parameter.
perform Perform a http request.
setAuthentication Set the user name, password and optionally domain for authentication purposes.
setCookie Set the active cookie string e.g. "name1=value1;name2=value2"
setCookieJar Set a file path to where a cookie jar should be read/stored.
setPostData Specify data to post when not using the onSend callback, with user-specified Content-Type.
setProxyAuthentication Set the user name and password for proxy authentication.
setTimeCondition Set time condition on the request.
setUserAgent Set the value of the user agent request header field.
shutdown Stop and invalidate this instance.

Inner structs

Name Description
StatusLine HTTP status line ie. the first line returned in an HTTP response.

Enums

Name Description
Method The standard HTTP methods : RFC2616 Section 5.1.1

Aliases

Name Description
AuthMethod Authentication method equal to etc.curl.CurlAuth
CurlProxy Type of proxy
requestAbort Value to return from onSend delegate in order to abort a request
requestPause Value to return from onSend/onReceive delegates in order to
TimeCond Time condition enumeration as an alias of etc.curl.CurlTimeCond

Example

import std.net.curl, std.stdio;

// Get with custom data receivers
auto http = HTTP("dlang.org");
http.onReceiveHeader =
    (in char[] key, in char[] value) { writeln(key ~ ": " ~ value); };
http.onReceive = (ubyte[] data) { /+ drop +/ return data.length; };
http.perform();

// Put with data senders
auto msg = "Hello world";
http.contentLength = msg.length;
http.onSend = (void[] data)
{
    auto m = cast(void[])msg;
    size_t len = m.length > data.length ? data.length : m.length;
    if (len == 0) return len;
    data[0..len] = m[0..len];
    msg = msg[len..$];
    return len;
};
http.perform();

// Track progress
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();

See Also

RFC2616

Authors

Jonas Drewsen. Some of the SMTP code contributed by Jimmy Cao.

License

Boost License 1.0.

Comments