On Tue, 07 Aug 2018 21:49:26 GMT, Johannes Loher wrote:

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 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).