arsd.cgi
- class Cgi;
- The main interface with the web request
- this(int maxContentLength = 5000000, string delegate(string env) getenv = null, const(ubyte)[] delegate() readdata = null, void delegate(const(ubyte)[]) _rawDataOutput = null);
- Initializes it using the CGI interface
- this(string[] headers, immutable(ubyte)[] data, string address, void delegate(const(ubyte)[]) _rawDataOutput = null, int pathInfoStarts = 0);
- Initializes it from some almost* raw HTTP request data
headers[0] should be the "GET / HTTP/1.1" line
Note the data should /not/ be chunked at this point.
headers:
each http header, excluding the \r\n at the end, but including the request line at headers[0]
data:
the request data (usually POST variables)
address:
the remote IP
rawDataOutput:
delegate to accept response data. If not null, this is called for all data output, which
will include HTTP headers and the status line. The data may also be chunked; it is already suitable for
being sent directly down the wire.
If null, the data is sent to stdout.
FIXME:
data should be able to be streaming, for large files
- void setCache(bool allowCaching);
- Very simple caching controls - setCache(false) means it will never be cached.
setCache(true) means it will always be cached for as long as possible.
Use setResponseExpires and updateResponseExpires for more control
- const string getCurrentCompleteUri();
- This gets a full url for the current request, including port, protocol, host, path, and query
- void setResponseStatus(string status);
- Sets the HTTP status of the response. For example, "404 File Not Found" or "500 Internal Server Error".
It assumes "200 OK", and automatically changes to "302 Found" if you call setResponseLocation().
Note setResponseStatus() must be called *before* you write() any data to the output.
- void setResponseLocation(string uri, bool important = true);
- Sets the location header, which the browser will redirect the user to automatically.
Note setResponseLocation() must be called *before* you write() any data to the output.
The optional important argument is used if it's a default suggestion rather than something to insist upon.
- void setResponseExpires(long when, bool isPublic = false);
- Sets the Expires: http header. See also: updateResponseExpires, setPublicCaching
The parameter is in unix_timestamp * 1000. Try setResponseExpires(getUTCtime() + SOME AMOUNT) for normal use.
Note:
the when parameter is different than setCookie's expire parameter.
- void updateResponseExpires(long when, bool isPublic);
- This is like setResponseExpires, but it can be called multiple times. The setting most in the past is the one kept.
If you have multiple functions, they all might call updateResponseExpires about their own return value. The program
output as a whole is as cacheable as the least cachable part in the chain.
setCache(false) always overrides this - it is, by definition, the strictest anti-cache statement available.
Conversely, setting here overrides setCache(true), since any expiration date is in the past of infinity.
- void setCookie(string name, string data, long expiresIn = 0, string path = null, string domain = null, bool httpOnly = false);
- Sets an HTTP cookie, automatically encoding the data to the correct string.
expiresIn is how many milliseconds in the future the cookie will expire.
TIP:
to make a cookie accessible from subdomains, set the domain to .yourdomain.com.
Note setCookie() must be called *before* you write() any data to the output.
- void clearCookie(string name, string path = null, string domain = null);
- Clears a previously set cookie with the given name, path, and domain.
- void setResponseContentType(string ct);
- Sets the content type of the response, for example "text/html" (the default) for HTML, or "image/png" for a PNG image
- void header(string h);
- Adds a custom header. It should be the name: value, but without any line terminator.
For example: header("X-My-Header: Some value");
Note you should use the specialized functions in this object if possible to avoid
duplicates in the output.
- void write(const(void)[] t, bool isAll = false);
- Writes the data to the output, flushing headers if they have not yet been sent.
- void close();
- Flushes the buffers to the network, signifying that you are done.
You should always call this explicitly when you are done outputting data.
- const nothrow T request(T = string)(in string name, in T def = T.init);
- Gets a request variable as a specific type, or the default value of it isn't there
or isn't convertable to the request type. Checks both GET and POST variables.
Page generated by Ddoc.