11use crate :: action:: Action ;
22use crate :: http:: { Header , Request } ;
33use serde:: { Deserialize , Serialize } ;
4+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
45
56#[ derive( Serialize , Deserialize , Debug , Clone ) ]
67pub struct Log {
@@ -27,7 +28,46 @@ struct FromLog {
2728 content_type : Option < String > ,
2829}
2930
31+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
32+ pub struct LegacyLog {
33+ status_code : u16 ,
34+ host : Option < String > ,
35+ method : Option < String > ,
36+ request_uri : Option < String > ,
37+ user_agent : Option < String > ,
38+ referer : Option < String > ,
39+ scheme : Option < String > ,
40+ use_json : Option < bool > ,
41+ target : Option < String > ,
42+ rule_id : Option < String > ,
43+ }
44+
3045impl Log {
46+ pub fn from_legacy ( legacy : LegacyLog , proxy : String ) -> Self {
47+ let now = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
48+ Err ( _) => 0 ,
49+ Ok ( time) => time. as_millis ( ) as u64 ,
50+ } ;
51+
52+ Log {
53+ code : legacy. status_code ,
54+ to : legacy. target . unwrap_or_default ( ) ,
55+ time : now,
56+ proxy,
57+ ips : None ,
58+ from : FromLog {
59+ rule_ids : legacy. rule_id . map ( |id| vec ! [ id] ) ,
60+ url : legacy. request_uri . unwrap_or_default ( ) ,
61+ method : legacy. method ,
62+ scheme : legacy. scheme ,
63+ host : legacy. host ,
64+ referer : legacy. referer ,
65+ user_agent : legacy. user_agent ,
66+ content_type : None ,
67+ } ,
68+ }
69+ }
70+
3171 pub fn from_proxy (
3272 request : & Request ,
3373 code : u16 ,
0 commit comments