View source code
							
							
						
								Display the source code in std/net/curl.d from which thispage was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create aBugzilla 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 usinglocal clone.
							
						Struct std.net.curl.HTTP
HTTP client functionality.
						
				struct HTTP;
						
					
				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 | HTTP 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. | 
								onReceiveHeader[set]
							 | 
							void delegate(in char[], in char[]) | Set the event handler that receives incoming headers. | 
								onReceiveStatusLine[set]
							 | 
							void delegate(HTTP | 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 | 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
								
								(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.
 | 
						
								
									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
| 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 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
Authors
Jonas Drewsen. Some of the SMTP code contributed by Jimmy Cao.
License
					Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.