RejectedSoftware Forums

Sign up

Request context

I am writting a class for storing user related data. Is there a way to read/write data from/to "request context"?
For example:

void auth(HTTPServerRequest req, HTTPServerResponse res) {
   User user = createUser(req); // creating User class based on request data (session)
   storeUser(req, user); // storing user data into request. How to do this?
}

void admin(HTTPServerRequest req, HTTPServerResponse res) {
  User user = loadUser(req);
  if(!user.isAdmin) throw new HTTPStatusException(HTTPStatus.forbidden);
  ...
}

shared static this() {
  ...
  router.get("*", &auth);
  router.get("/admin", &admin);
  ...
}

Also has vibe.d some API for read/write data from/to Task/Fiber Local Storage?

Re: Request context

On Sat, 20 Jul 2013 14:30:46 GMT, Jack Applegame wrote:

I am writting a class for storing user related data. Is there a way to read/write data from/to "request context"?
For example:

(...)

There is the HTTPServerRequest.params map, which is supposed to be used in situations like these. It currently is just a string[string] map, though. I've been thinking about making it Variant[string] instead, but I need to look into how to do this without breaking existing code first.

Also has vibe.d some API for read/write data from/to Task/Fiber Local Storage?

Yes, there is vibe.core.core.setTaskLocal and vibe.core.core.getTaskLocal which stores arbitrary data in a per-task Variant[string} map. This should be usable as a workaround for now.

Re: Request context

Thanks.
I'll use task local storage instead request storage.