View source code
Display the source code in std/net/curl.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

Struct std.net.curl.HTTP

HTTP client functionality.

struct HTTP ;

Properties

NameTypeDescription
authenticationMethod[set] CurlAuthAuthentication method as specified in AuthMethod.
caInfo[set] const(char)[]Set the CA certificate bundle file to use for SSL peer verification
connectTimeout[set] DurationSet timeout for connecting.
contentLength[set] ulongThe 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] DurationSet timeout for activity on connection.
defaultUserAgent[get] stringThe default "User-Agent" value send with a request. It has the form "Phobos-std.net.curl/PHOBOS_VERSION (libcurl/CURL_VERSION)"
dnsTimeout[set] DurationDNS lookup timeout.
isStopped[get] boolTrue if the instance is stopped. A stopped instance is not usable.
localPort[set] ushortSet the local outgoing port to use.
localPortRange[set] ushortSet the local outgoing port range to use. This can be used together with the localPort property.
maxRedirects[set] uintSet max allowed redirections using the location header. uint.max for infinite.
method[get, set] HTTP.MethodHTTP method used.
netInterface[set] const(char)[]The network interface to use in form of 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.
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] DurationSet 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] ushortProxy port
proxyType[set] CurlProxyProxy type
responseHeaders[get] string[string]The headers read from a successful response.
statusLine[get] HTTP.StatusLineHTTP status line of last response. One call to perform may result in several requests because of redirection.
tcpNoDelay[set] boolSet the tcp no-delay socket option on or off.
url[set] const(char)[]The URL to specify the location of the resource.
verbose[set] boolSet verbose. This will print request information to stderr.

Methods

NameDescription
addRequestHeader (name, value) Add a header e.g. "X-CustomField: Something is fishy".
clearAllCookies () Clear all cookies.
clearRequestHeaders () Clear all outgoing headers.
clearSessionCookies () Clear session cookies.
dup ()
flushCookieJar () Flush cookie jar to disk.
getTiming (timing, val) Get various timings defined in CurlInfo. The value is usable only if the return value is equal to CurlError.ok.
onReceiveHeader () Set the event handler that receives incoming headers.
opCall (url) Constructor taking the url as parameter.
opCall ()
perform (throwOnError) Perform a http request.
setAuthentication (username, password, domain) Set the user name, password and optionally domain for authentication purposes.
setCookie (cookie) Set the active cookie string e.g. "name1=value1;name2=value2"
setCookieJar (path) Set a file path to where a cookie jar should be read/stored.
setPostData (data, contentType) Specify data to post when not using the onSend callback, with user-specified Content-Type.
setProxyAuthentication (username, password) Set the user name and password for proxy authentication.
setTimeCondition (cond, timestamp) Set time condition on the request.
setUserAgent (userAgent) Set the value of the user agent request header field.
shutdown () Stop and invalidate this instance.

Inner structs

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

Enums

NameDescription
Method The standard HTTP methods : RFC2616 Section 5.1.1

Aliases

NameDescription
AuthMethod Authentication method equal to 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 pause a request
TimeCond Time condition enumeration as an alias of CurlTimeCond

Example

Get with custom data receivers:

import std.net.curl, std.stdio;

auto http = HTTP("https://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:

import std.net.curl, std.stdio;

auto http = HTTP("https://dlang.org");
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();

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();

See Also

RFC2616

Authors

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

License

Boost License 1.0.