Skip to content

Commit b708c64

Browse files
committed
feat(agent): support old proxy endpoints
1 parent 5d6c370 commit b708c64

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/api/log.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::action::Action;
22
use crate::http::{Header, Request};
33
use serde::{Deserialize, Serialize};
4+
use std::time::{SystemTime, UNIX_EPOCH};
45

56
#[derive(Serialize, Deserialize, Debug, Clone)]
67
pub 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+
3045
impl 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,

src/api/marker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66
pub struct Marker {
77
pub name: String,
88
pub regex: String,
9-
#[serde(skip_serializing_if = "Vec::is_empty", default)]
9+
#[serde(default)]
1010
pub transformers: Vec<Transformer>,
1111
}
1212

src/api/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod trace;
1414
mod transformer;
1515
mod variable;
1616

17-
pub use self::log::Log;
17+
pub use self::log::{LegacyLog, Log};
1818
pub use body_filter::{BodyFilter, HTMLBodyFilter, TextAction, TextBodyFilter};
1919
pub use header::Header;
2020
pub use header_filter::HeaderFilter;

0 commit comments

Comments
 (0)