Function Session.opApply
Enables foreach-iteration over all keys of the session.
Prototype
int opApply(
scope int delegate(string) del
);
Example
//import vibe.http.server;
// workaround for cyclic module ctor compiler error
class HTTPServerRequest { Session session; }
class HTTPServerResponse { import vibe .core .stream; OutputStream bodyWriter() { assert(false); } string contentType; }
// sends all session entries to the requesting browser
// assumes that all entries are strings
void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res)
{
res .contentType = "text/plain";
foreach(key; req .session)
res .bodyWriter .write(key ~ ": " ~ req .session .get!string(key) ~ "\n");
}
}
/**
Gets/sets a key/value pair stored within the session.
Returns null if the specified key is not set.
Examples:
void handleRequest(HTTPServerRequest req, HTTPServerResponse res) { res.contentType = "text/plain";
res.bodyWriter.write("Username: " ~ req.session["userName"]); res.bodyWriter.write("Request count: " ~ req.session["requestCount"]); req.session["requestCount"] = to!string(req.session["requestCount"].to!int + 1);
Authors
Jan Krüger, Sönke Ludwig, Ilya Shipunov
Copyright
© 2012-2013 RejectedSoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.