1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! [`Observer`] trait and function implementations.
use Duration;
use ServiceRequest;
use StatusCode;
use BytesMut;
use Uuid;
/// Request start arguments container
///
/// # Properties
///
/// * `req` - borrowed ServiceRequest.
/// * `request_id` - unique identifier of a request, identifies connection between request start and end.
/// * `uri` - uri of request.
/// * `method` - http method of request.
/// Request end arguments container
///
/// # Properties
///
/// * `request_id` - unique identifier of a request, identifies connection between request start and end.
/// * `elapsed` - elapsed time between request start and end hook.
/// * `uri` - uri of request.
/// * `method` - http method of request.
/// * `status` - http status code of response.
/// An Observer is notified before a request is passed for processing, and after processing into a response.
/// Use case could be logging before and after request:
/// ```
/// use actix_request_hook::observer::{Observer, RequestEndData, RequestStartData};
/// struct RequestLogger;
///
/// impl Observer for RequestLogger {
/// fn on_request_started(&self, data: RequestStartData) {
/// println!("[start - {}] {} {}", data.request_id.to_string(), data.method, data.uri);
/// }
///
/// fn on_request_ended(&self, data: RequestEndData) {
/// let time_elapsed_millis = data.elapsed.as_millis();
/// println!("[end - {}] {} {} ended with {} after {}ms", data.request_id.to_string(), data.method, data.uri, data.status, time_elapsed_millis);
/// }
/// }
///
/// ```