The OpenD Programming Language

HttpRequest

Represents a HTTP request. You usually create these through a HttpClient.

More...

Constructors

this
this(HttpClient client, Uri where, HttpVerb method, ICache cache, Duration timeout, string proxy)
this(Uri where, HttpVerb method, ICache cache, Duration timeout, string proxy)

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

abort
void abort()

Aborts this request.

gzipBody
void gzipBody(bool want)

Set to true to gzip the request body when sending to the server. This is often not supported, and thus turned off by default.

perform
HttpResponse perform()

Sends now and waits for the request to finish, returning the response.

send
void send()

Sends the request asynchronously.

setMaximumNumberOfRedirects
void setMaximumNumberOfRedirects(int max)

Maximum number of redirections to follow (used only if followLocation is set to true). Will resolve with an error if a single request has more than this number of redirections. The default value is currently 10, but may change without notice. If you need a specific value, be sure to call this function.

setTimeout
void setTimeout(Duration timeout)

Sets the timeout from inactivity on the request. This is the amount of time that passes with no send or receive activity on the request before it fails with "request timed out" error.

waitForCompletion
HttpResponse waitForCompletion()

Waits for the request to finish or timeout, whichever comes first.

Static functions

advanceConnections
int advanceConnections(Duration maximumTimeout, bool automaticallyRetryOnInterruption)

This is made public for rudimentary event loop integration, but is still basically an internal detail. Try not to use it if you have another way.

setConnectionCacheSize
void setConnectionCacheSize(int max)

Changes the limit of number of open, inactive sockets. Reusing connections can provide a significant performance improvement, but the operating system can also impose a global limit on the number of open sockets and/or files that you don't want to run into. This lets you choose a balance right for you.

Variables

finalUrl
string finalUrl;

Final url after any redirections

followLocation
bool followLocation;

Automatically follow a redirection?

onDataReceived
void delegate(HttpRequest) onDataReceived;

Called when data is received. Check the state to see what data is available.

proxy
string proxy;

Proxy to use for this request. It should be a URL or null.

requestParameters
HttpRequestParameters requestParameters;
retainCookies
bool retainCookies;

Set to true to automatically retain cookies in the associated HttpClient from this request. Note that you must have constructed the request from a HttpClient or at least passed one into the constructor for this to have any effect.

verifyPeer
bool verifyPeer;

For https connections, if this is true, it will fail to connect if the TLS certificate can not be verified. Setting this to false will skip this check and allow the connection to continue anyway.

Detailed Description

auto request = new HttpRequest(); // note that when there's no associated client, some features may not work
// normally you'd instead do `new HttpClient(); client.request(...)`
// set any properties here

// synchronous usage
auto reply = request.perform();

// async usage, type 1:
request.send();
request2.send();

// wait until the first one is done, with the second one still in-flight
auto response = request.waitForCompletion();

// async usage, type 2:
request.onDataReceived = (HttpRequest hr) {
	if(hr.state == HttpRequest.State.complete) {
		// use hr.responseData
	}
};
request.send(); // send, using the callback

// before terminating, be sure you wait for your requests to finish!

request.waitForCompletion();

Meta