vibe.d: Finding out if currently in webinterface request
Johannes Loher
johannes.loher at fg4f.de
Thu Aug 9 21:59:24 UTC 2018
I already posted this in the vibe.d forums
(https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/58891/), but it seems, there is not a lot of activity over there, so I am cross posting this here:
Is there a way to find out, if we are currently in a webinterface
request?
My usecase is the following:
I want to implement a logger, which in addition to the actual log
message also logs information about the request which is
currently being handled (if any). For this I would like to call
request(), which gives me the current HTTPServerRequest. However,
this results in an AssertError, whenever logging appears outside
of a webinterface request (so basically immediately after
starting the application, because vibe.d logs some things
automatically). So I would need to check, if we are currently
processing a webinterface request.
Another usecase which would be interesting to me and which has
the exact same problem is the following:
Suppose in my received request, there is an HTTP header
X-Correlation-Id: <uuid>. Now whenever during processing of this
request I start an HTTP request to some other service (e.g. via
requestHTTP()), I also want to include this header in the new
request I send. Of course, you could implement this by always
passing the header manually, but I'd prefer to implement this
using a generalized wrapper around requestHTTP(). But then in
this wrapper, I would also need to call request(), which makes it
impossible to call it from outside of webinterface request (e.g.
it could be triggered by a timer, or something like this). But it
would be nice, to be able to just use a single function for all
my requests (to keep things uniform).
More information about the Digitalmars-d-learn
mailing list