diff --git a/src/protocol/v7.rs b/src/protocol/v7.rs index 49e9d0a1..64fdcbb8 100644 --- a/src/protocol/v7.rs +++ b/src/protocol/v7.rs @@ -313,16 +313,20 @@ pub struct User { #[serde(default)] pub struct Request { /// The current URL of the request. - #[serde(with = "url_serde")] + #[serde(with = "url_serde", skip_serializing_if = "Option::is_none")] pub url: Option, /// The HTTP request method. + #[serde(skip_serializing_if = "Option::is_none")] pub method: Option, /// Optionally some associated request data (human readable) // XXX: this makes absolutely no sense because of unicode + #[serde(skip_serializing_if = "Option::is_none")] pub data: Option, /// Optionally the encoded query string. + #[serde(skip_serializing_if = "Option::is_none")] pub query_string: Option, /// An encoded cookie string if available. + #[serde(skip_serializing_if = "Option::is_none")] pub cookies: Option, /// HTTP request headers. #[serde(skip_serializing_if = "HashMap::is_empty")] diff --git a/tests/test_protocol_v7.rs b/tests/test_protocol_v7.rs index 33408104..b2d27769 100644 --- a/tests/test_protocol_v7.rs +++ b/tests/test_protocol_v7.rs @@ -223,6 +223,40 @@ fn test_user() { ); } +#[test] +fn test_request() { + let event = v7::Event { + request: Some(v7::Request { + url: "https://www.example.invalid/bar".parse().ok(), + method: Some("GET".into()), + data: Some("{}".into()), + query_string: Some("foo=bar&blub=blah".into()), + cookies: Some("dummy=42".into()), + headers: { + let mut hm = HashMap::new(); + hm.insert("Content-Type".into(), "text/plain".into()); + hm + }, + env: { + let mut env = HashMap::new(); + env.insert("PATH_INFO".into(), "/bar".into()); + env + }, + ..Default::default() + }), + ..Default::default() + }; + + assert_eq!( + serde_json::to_string(&event).unwrap(), + "{\"request\":{\"url\":\"https://www.example.invalid/bar\",\ + \"method\":\"GET\",\"data\":\"{}\",\"query_string\":\ + \"foo=bar&blub=blah\",\"cookies\":\"dummy=42\",\"headers\":\ + {\"Content-Type\":\"text/plain\"},\"env\":\ + {\"PATH_INFO\":\"/bar\"}}}" + ); +} + #[test] fn test_canonical_exception() { let mut event: v7::Event = Default::default();