Skip to content

Commit c9f4ff3

Browse files
committed
feat(headers): export missing header types
1 parent 2a49cee commit c9f4ff3

File tree

4 files changed

+74
-37
lines changed

4 files changed

+74
-37
lines changed

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

-30
This file was deleted.

src/header/common/last_event_id.rs

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use std::fmt::{self, Display};
2+
use header::{self, Header, Raw};
3+
4+
/// `Last-Event-ID` header, defined in
5+
/// [RFC3864](https://html.spec.whatwg.org/multipage/references.html#refsRFC3864)
6+
///
7+
/// The `Last-Event-ID` header contains information about
8+
/// the last event in an http interaction so that it's easier to
9+
/// track of event state. This is helpful when working
10+
/// with [Server-Sent-Events](http://www.html5rocks.com/en/tutorials/eventsource/basics/). If the connection were to be dropped, for example, it'd
11+
/// be useful to let the server know what the last event you
12+
/// received was.
13+
///
14+
/// The spec is a String with the id of the last event, it can be
15+
/// an empty string which acts a sort of "reset".
16+
///
17+
/// # Example
18+
/// ```
19+
/// use hyper::header::{Headers, LastEventId};
20+
///
21+
/// let mut headers = Headers::new();
22+
/// headers.set(LastEventId("1".to_owned()));
23+
/// ```
24+
#[derive(Clone, Debug, PartialEq)]
25+
pub struct LastEventId(pub String);
26+
27+
impl Header for LastEventId {
28+
#[inline]
29+
fn header_name() -> &'static str {
30+
static NAME: &'static str = "Last-Event-ID";
31+
NAME
32+
}
33+
34+
#[inline]
35+
fn parse_header(raw: &Raw) -> ::Result<Self> {
36+
match raw.one() {
37+
Some(line) if line.is_empty() => Ok(LastEventId("".to_owned())),
38+
Some(line) => header::parsing::from_raw_str(line).map(LastEventId),
39+
None => Err(::Error::Header),
40+
}
41+
}
42+
43+
#[inline]
44+
fn fmt_header(&self, f: &mut header::Formatter) -> fmt::Result {
45+
f.fmt_line(self)
46+
}
47+
}
48+
49+
impl Display for LastEventId {
50+
#[inline]
51+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52+
Display::fmt(&self.0, f)
53+
}
54+
}
55+
56+
__hyper__deref!(LastEventId => String);
57+
58+
__hyper__tm!(LastEventId, tests {
59+
// Initial state
60+
test_header!(test1, vec![b""]);
61+
// Own testcase
62+
test_header!(test2, vec![b"1"], Some(LastEventId("1".to_owned())));
63+
});

src/header/common/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub use self::if_modified_since::IfModifiedSince;
4242
pub use self::if_none_match::IfNoneMatch;
4343
pub use self::if_range::IfRange;
4444
pub use self::if_unmodified_since::IfUnmodifiedSince;
45+
pub use self::last_event_id::LastEventId;
4546
pub use self::last_modified::LastModified;
4647
pub use self::link::{Link, LinkValue, RelationType, MediaDesc};
4748
pub use self::location::Location;
@@ -56,6 +57,7 @@ pub use self::retry_after::RetryAfter;
5657
pub use self::server::Server;
5758
pub use self::set_cookie::SetCookie;
5859
pub use self::strict_transport_security::StrictTransportSecurity;
60+
pub use self::te::Te;
5961
pub use self::transfer_encoding::TransferEncoding;
6062
pub use self::upgrade::{Upgrade, Protocol, ProtocolName};
6163
pub use self::user_agent::UserAgent;
@@ -474,6 +476,7 @@ mod if_modified_since;
474476
mod if_none_match;
475477
mod if_range;
476478
mod if_unmodified_since;
479+
mod last_event_id;
477480
mod last_modified;
478481
mod link;
479482
mod location;
@@ -488,6 +491,7 @@ mod retry_after;
488491
mod server;
489492
mod set_cookie;
490493
mod strict_transport_security;
494+
mod te;
491495
mod transfer_encoding;
492496
mod upgrade;
493497
mod user_agent;

src/header/common/te.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,38 @@ header! {
2525
///
2626
/// # Examples
2727
/// ```
28-
/// use hyper::header::{Headers, TE, Encoding, qitem};
28+
/// use hyper::header::{Headers, Te, Encoding, qitem};
2929
///
3030
/// let mut headers = Headers::new();
3131
/// headers.set(
32-
/// TE(vec![qitem(Encoding::Trailers)])
32+
/// Te(vec![qitem(Encoding::Trailers)])
3333
/// );
3434
/// ```
3535
/// ```
36-
/// use hyper::header::{Headers, TE, Encoding, qitem};
36+
/// use hyper::header::{Headers, Te, Encoding, qitem};
3737
///
3838
/// let mut headers = Headers::new();
3939
/// headers.set(
40-
/// TE(vec![
40+
/// Te(vec![
4141
/// qitem(Encoding::Trailers),
4242
/// qitem(Encoding::Gzip),
4343
/// qitem(Encoding::Deflate),
4444
/// ])
4545
/// );
4646
/// ```
4747
/// ```
48-
/// use hyper::header::{Headers, TE, Encoding, QualityItem, q, qitem};
48+
/// use hyper::header::{Headers, Te, Encoding, QualityItem, q, qitem};
4949
///
5050
/// let mut headers = Headers::new();
5151
/// headers.set(
52-
/// TE(vec![
52+
/// Te(vec![
5353
/// qitem(Encoding::Trailers),
5454
/// QualityItem::new(Encoding::Gzip, q(600)),
5555
/// QualityItem::new(Encoding::EncodingExt("*".to_owned()), q(0)),
5656
/// ])
5757
/// );
5858
/// ```
59-
(TE, "TE") => (QualityItem<Encoding>)*
59+
(Te, "TE") => (QualityItem<Encoding>)*
6060

6161
test_te {
6262
// From the RFC

0 commit comments

Comments
 (0)