-
Notifications
You must be signed in to change notification settings - Fork 0
HTTP module
Ligustah edited this page Oct 4, 2011
·
2 revisions
The HTTP module contains several basic means of communicating the upstream server and client (e.g. setting cookies and HTTP headers). TODO: add documentation for Cookie class, http.env and http.cookies.
addCookie(cookie : Cookie)
Adds the supplied cookie instance to be sent to the client.
addHeader(header : string, value : string)
Adds a header to be sent to the client. Note that the header string needs to include the colon.
Example: addHeader("Content-Type:", "text/html")
For convenience the HTTP module defines several header constants like 'header.ContentType'.
setResponseCode(code : int)
Sets the HTTP response code (e.g. 200, 404, 302, etc).
For convenience the HTTP modules defines several response code constants like 'responseCode.Found'.
redirect(url : string)
Redirects the client browser to a different URL by setting a Location: header and sending a responseCode.Found (302).
All content sent will/should be ignored by the client.
module test
import http : Cookie
http.addHeader(http.header.ContentType, "text/plain")
http.setResponseCode(http.responseCode.OK)
foreach(k,v; http.env)
{
writefln $ "{} = {}", k, v
}
writeln()
foreach(k,v; http.cookies)
{
writefln $ "{} = {}", k, v.value
}