Hi Scott.
Here is one way to do it: Use the 'after_build_tx'-hook to register a
'progress' callback, which is about the earliest point in the
request's lifecycle to tap in. The callback will trigger "whenever
there is progress parsing the request" and receive the trnsaction's
request object as first argument. Just return from the callback until
parsing the request headers is finished. Then add your own request
header with a generated request ID and unsubscribe from the 'progress'
event to avoid triggering the callback for every body chunk for
performance reasons:
$app->hook(
after_build_tx => sub {
my $tx = shift;
$tx->req->on(progress => sub {
$_[0]->headers->is_finished or return;
$_[0]->headers->header('X-RID' => gen_req_id());
$_[0]->unsubscribe('progress');
});
});
);
You could then write a helper that first look into the stash for the
request ID and, if it doesn't find it there, extracts it from your
custom header, stashes it and then returns it. Caching it on the stash
may be more efficient but I don't have benchmarks to back that up.
-Cornelius
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
mojolicious...@googlegroups.com.
> To post to this group, send email to
mojol...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/mojolicious.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>