Skip to content

Commit e1542a6

Browse files
puhrezseanmonstar
authored andcommitted
feat(headers): add last-event-id header
Add a Last-Event-ID header to properly work with Server-Sent Events Addresses # 723
1 parent e226453 commit e1542a6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/header/common/last-event-id.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
header! {
2+
/// `Last-Event-ID` header, defined in
3+
/// [RFC3864](https://html.spec.whatwg.org/multipage/references.html#refsRFC3864)
4+
///
5+
/// The `Last-Event-ID` header contains information about
6+
/// the last event in an http interaction so that it's easier to
7+
/// track of event state. This is helpful when working
8+
/// with [Server-Sent-Events](http://www.html5rocks.com/en/tutorials/eventsource/basics/). If the connection were to be dropped, for example, it'd
9+
/// be useful to let the server know what the last event you
10+
/// recieved was.
11+
///
12+
/// The spec is a String with the id of the last event, it can be
13+
/// an empty string which acts a sort of "reset".
14+
///
15+
/// # Example
16+
/// ```
17+
/// use hyper::header::{Headers, LastEventID};
18+
///
19+
/// let mut headers = Headers::new();
20+
/// headers.set(LastEventID("1".to_owned()));
21+
/// ```
22+
(LastEventID, "Last-Event-ID") => [String]
23+
24+
test_last_event_id {
25+
// Initial state
26+
test_header!(test1, vec![b""]);
27+
// Own testcase
28+
test_header!(test2, vec![b"1"], Some(LastEventID("1".to_owned())));
29+
}
30+
}

0 commit comments

Comments
 (0)