Skip to content

Commit a1436e4

Browse files
committed
feat: Added basic request type
1 parent de1ebb0 commit a1436e4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/protocol/v7.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,20 @@ pub struct User {
313313
#[serde(default)]
314314
pub struct Request {
315315
/// The current URL of the request.
316-
#[serde(with = "url_serde")]
316+
#[serde(with = "url_serde", skip_serializing_if = "Option::is_none")]
317317
pub url: Option<Url>,
318318
/// The HTTP request method.
319+
#[serde(skip_serializing_if = "Option::is_none")]
319320
pub method: Option<String>,
320321
/// Optionally some associated request data (human readable)
321322
// XXX: this makes absolutely no sense because of unicode
323+
#[serde(skip_serializing_if = "Option::is_none")]
322324
pub data: Option<String>,
323325
/// Optionally the encoded query string.
326+
#[serde(skip_serializing_if = "Option::is_none")]
324327
pub query_string: Option<String>,
325328
/// An encoded cookie string if available.
329+
#[serde(skip_serializing_if = "Option::is_none")]
326330
pub cookies: Option<String>,
327331
/// HTTP request headers.
328332
#[serde(skip_serializing_if = "HashMap::is_empty")]

tests/test_protocol_v7.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,40 @@ fn test_user() {
223223
);
224224
}
225225

226+
#[test]
227+
fn test_request() {
228+
let event = v7::Event {
229+
request: Some(v7::Request {
230+
url: "https://www.example.invalid/bar".parse().ok(),
231+
method: Some("GET".into()),
232+
data: Some("{}".into()),
233+
query_string: Some("foo=bar&blub=blah".into()),
234+
cookies: Some("dummy=42".into()),
235+
headers: {
236+
let mut hm = HashMap::new();
237+
hm.insert("Content-Type".into(), "text/plain".into());
238+
hm
239+
},
240+
env: {
241+
let mut env = HashMap::new();
242+
env.insert("PATH_INFO".into(), "/bar".into());
243+
env
244+
},
245+
..Default::default()
246+
}),
247+
..Default::default()
248+
};
249+
250+
assert_eq!(
251+
serde_json::to_string(&event).unwrap(),
252+
"{\"request\":{\"url\":\"https://www.example.invalid/bar\",\
253+
\"method\":\"GET\",\"data\":\"{}\",\"query_string\":\
254+
\"foo=bar&blub=blah\",\"cookies\":\"dummy=42\",\"headers\":\
255+
{\"Content-Type\":\"text/plain\"},\"env\":\
256+
{\"PATH_INFO\":\"/bar\"}}}"
257+
);
258+
}
259+
226260
#[test]
227261
fn test_canonical_exception() {
228262
let mut event: v7::Event = Default::default();

0 commit comments

Comments
 (0)