Skip to content

Commit 507f15a

Browse files
authored
Merge pull request #315 from http-rs/header-trait
Implement the `Header` trait
2 parents bf5ace6 + 338508d commit 507f15a

33 files changed

+340
-11
lines changed

src/auth/authorization.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::auth::AuthenticationScheme;
22
use crate::bail_status as bail;
3-
use crate::headers::{HeaderName, HeaderValue, Headers, AUTHORIZATION};
3+
use crate::headers::{Header, HeaderName, HeaderValue, Headers, AUTHORIZATION};
44

55
/// Credentials to authenticate a user agent with a server.
66
///
@@ -78,7 +78,7 @@ impl Authorization {
7878

7979
/// Get the `HeaderName`.
8080
pub fn name(&self) -> HeaderName {
81-
AUTHORIZATION
81+
self.header_name()
8282
}
8383

8484
/// Get the `HeaderValue`.
@@ -110,6 +110,16 @@ impl Authorization {
110110
}
111111
}
112112

113+
impl Header for Authorization {
114+
fn header_name(&self) -> HeaderName {
115+
AUTHORIZATION
116+
}
117+
118+
fn header_value(&self) -> HeaderValue {
119+
self.value()
120+
}
121+
}
122+
113123
#[cfg(test)]
114124
mod test {
115125
use super::*;

src/auth/basic_auth.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ impl BasicAuth {
113113
}
114114
}
115115

116+
impl crate::headers::Header for BasicAuth {
117+
fn header_name(&self) -> HeaderName {
118+
AUTHORIZATION
119+
}
120+
121+
fn header_value(&self) -> HeaderValue {
122+
self.value()
123+
}
124+
}
125+
116126
#[cfg(test)]
117127
mod test {
118128
use super::*;

src/auth/www_authenticate.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ impl WwwAuthenticate {
132132
}
133133
}
134134

135+
impl crate::headers::Header for WwwAuthenticate {
136+
fn header_name(&self) -> HeaderName {
137+
WWW_AUTHENTICATE
138+
}
139+
140+
fn header_value(&self) -> HeaderValue {
141+
self.value()
142+
}
143+
}
144+
135145
#[cfg(test)]
136146
mod test {
137147
use super::*;

src/cache/age.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ impl ToHeaderValues for Age {
9595
}
9696
}
9797

98+
impl crate::headers::Header for Age {
99+
fn header_name(&self) -> HeaderName {
100+
AGE
101+
}
102+
103+
fn header_value(&self) -> HeaderValue {
104+
self.value()
105+
}
106+
}
107+
98108
#[cfg(test)]
99109
mod test {
100110
use super::*;

src/cache/cache_control/cache_control.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ impl CacheControl {
104104
}
105105
}
106106

107+
impl crate::headers::Header for CacheControl {
108+
fn header_name(&self) -> HeaderName {
109+
CACHE_CONTROL
110+
}
111+
fn header_value(&self) -> HeaderValue {
112+
self.value()
113+
}
114+
}
115+
107116
impl IntoIterator for CacheControl {
108117
type Item = CacheDirective;
109118
type IntoIter = IntoIter;

src/cache/clear_site_data/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ impl Debug for ClearSiteData {
249249
}
250250
}
251251

252+
impl crate::headers::Header for ClearSiteData {
253+
fn header_name(&self) -> HeaderName {
254+
CLEAR_SITE_DATA
255+
}
256+
fn header_value(&self) -> HeaderValue {
257+
self.value()
258+
}
259+
}
260+
252261
#[cfg(test)]
253262
mod test {
254263
use crate::cache::{ClearDirective, ClearSiteData};

src/cache/expires.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ impl Expires {
9090
}
9191
}
9292

93+
impl crate::headers::Header for Expires {
94+
fn header_name(&self) -> HeaderName {
95+
EXPIRES
96+
}
97+
fn header_value(&self) -> HeaderValue {
98+
self.value()
99+
}
100+
}
101+
93102
impl ToHeaderValues for Expires {
94103
type Iter = option::IntoIter<HeaderValue>;
95104
fn to_header_values(&self) -> crate::Result<Self::Iter> {

src/conditional/etag.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ impl ETag {
130130
}
131131
}
132132

133+
impl crate::headers::Header for ETag {
134+
fn header_name(&self) -> HeaderName {
135+
ETAG
136+
}
137+
fn header_value(&self) -> HeaderValue {
138+
self.value()
139+
}
140+
}
141+
133142
impl Display for ETag {
134143
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
135144
match self {

src/conditional/if_match.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ impl IfMatch {
134134
}
135135
}
136136

137+
impl crate::headers::Header for IfMatch {
138+
fn header_name(&self) -> HeaderName {
139+
IF_MATCH
140+
}
141+
fn header_value(&self) -> HeaderValue {
142+
self.value()
143+
}
144+
}
145+
137146
impl IntoIterator for IfMatch {
138147
type Item = ETag;
139148
type IntoIter = IntoIter;

src/conditional/if_modified_since.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ impl ToHeaderValues for IfModifiedSince {
9393
}
9494
}
9595

96+
impl crate::headers::Header for IfModifiedSince {
97+
fn header_name(&self) -> HeaderName {
98+
IF_MODIFIED_SINCE
99+
}
100+
fn header_value(&self) -> HeaderValue {
101+
self.value()
102+
}
103+
}
104+
96105
#[cfg(test)]
97106
mod test {
98107
use super::*;

0 commit comments

Comments
 (0)