You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a simple fairing doing time measurements for the request. What we do is we capture "start" time in the on_request handler and measure elapsed time in the on_response handler.
Unfortunately, it seems like there are not a lot of options to save that "start" timestamp. One can add a header to the request and check it later in the response, but that requires converting timestamp into a string (and it seems std::time::Instant is not friendly to to_string/parse). Also, that opens a potential attack as headers are partially under the control of the caller (you have to be careful to use replace_header versus add_header).
Other option would be to use thread-local, which is probably going to work, but can we rely that on_response would be called on the same thread? I think, we can, but documentation does not mention that explicitly.
Or maybe keep our own hash map, but then we need a way to identify a request and also to make sure that we clean that map no matter what (like, request catastrophically fails that on_response is never called).
The version of Rocket this question is based on, if any.
0.3.6
What steps you've taken to answer the question yourself.
Searched issues, looked at the Request API, looked at the fairings API
What documentation you believe should include an answer to this question.
Fairing documentation should mention thread local as an option (if that is an option). Also, having an example that measures the processing time would be helpful (versus an example that only counts requests) -- this is probably very common use-case.
The text was updated successfully, but these errors were encountered:
We have a simple fairing doing time measurements for the request. What we do is we capture "start" time in the
on_request
handler and measure elapsed time in theon_response
handler.Unfortunately, it seems like there are not a lot of options to save that "start" timestamp. One can add a header to the request and check it later in the response, but that requires converting timestamp into a string (and it seems
std::time::Instant
is not friendly to to_string/parse). Also, that opens a potential attack as headers are partially under the control of the caller (you have to be careful to usereplace_header
versusadd_header
).Other option would be to use thread-local, which is probably going to work, but can we rely that
on_response
would be called on the same thread? I think, we can, but documentation does not mention that explicitly.Or maybe keep our own hash map, but then we need a way to identify a request and also to make sure that we clean that map no matter what (like, request catastrophically fails that
on_response
is never called).0.3.6
Searched issues, looked at the Request API, looked at the fairings API
Fairing documentation should mention thread local as an option (if that is an option). Also, having an example that measures the processing time would be helpful (versus an example that only counts requests) -- this is probably very common use-case.
The text was updated successfully, but these errors were encountered: