Skip to content

Commit

Permalink
Make VercelProxy::user_agent optional (missing for middleware-invoc…
Browse files Browse the repository at this point in the history
…ation), add `Message` fields `status_code`, `execution_region` and `level`. (#23)
  • Loading branch information
miceg authored Sep 5, 2024
1 parent 836bf7f commit 90d7bf0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mod tests {
include_str!("fixtures/sample_3.json"),
include_str!("fixtures/sample_4.json"),
include_str!("fixtures/sample_5.json"),
include_str!("fixtures/sample_6.json"),
// Vercel's test requests, missing projectName field
include_str!("fixtures/test_build.json"),
include_str!("fixtures/test_edge.json"),
Expand Down Expand Up @@ -89,7 +90,7 @@ mod tests {
);
assert_eq!(response.status(), StatusCode::OK);
}
assert_eq!(rx.len(), 14);
assert_eq!(rx.len(), 15);
Ok(())
}
#[tokio::test]
Expand Down
28 changes: 28 additions & 0 deletions src/fixtures/sample_6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"id": "1706327928080727830237235800",
"message": "[GET] [middleware: \"middleware\"] / status=200",
"timestamp": 1706327928080,
"type": "middleware-invocation",
"requestId": "abc1-1706327928072-6ecc9b4dfbf3",
"executionRegion": "abc1",
"statusCode": 200,
"level": "info",
"proxy": {
"timestamp": 1706327928072,
"region": "abc1",
"clientIp": "192.0.2.3",
"method": "GET",
"path": "/",
"scheme": "https",
"host": "example.com"
},
"projectId": "prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"projectName": "example",
"deploymentId": "dpl_xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"source": "edge",
"host": "example.vercel.app",
"path": "middleware",
"environment": "production"
}
]
5 changes: 5 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub struct Message {
pub request_id: Option<String>,
#[allow(private_interfaces)]
pub proxy: Option<VercelProxy>,
pub status_code: Option<i16>,
pub execution_region: Option<String>,
pub level: Option<String>,
}

fn deserialize_message_data<'de, D>(deserializer: D) -> Result<serde_json::Value, D::Error>
Expand Down Expand Up @@ -108,6 +111,7 @@ struct VercelProxy {
method: String,
scheme: String,
host: String,
#[serde(default)]
user_agent: Vec<String>,
referer: Option<String>,
status_code: Option<isize>,
Expand Down Expand Up @@ -135,6 +139,7 @@ mod test {
include_str!("fixtures/sample_3.json"),
include_str!("fixtures/sample_4.json"),
include_str!("fixtures/sample_5.json"),
include_str!("fixtures/sample_6.json"),
// Vercel's test requests, missing projectName field
include_str!("fixtures/test_build.json"),
include_str!("fixtures/test_edge.json"),
Expand Down

0 comments on commit 90d7bf0

Please sign in to comment.