Skip to content

Commit 7516664

Browse files
committed
Add Header trait
Fixed headers: TE, TransferEncoding
1 parent f955922 commit 7516664

33 files changed

+330
-10
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use anyhow::bail;
2+
13
use crate::auth::{AuthenticationScheme, Authorization};
24
use crate::headers::{HeaderName, HeaderValue, Headers, AUTHORIZATION};
35
use crate::Status;
@@ -113,6 +115,16 @@ impl BasicAuth {
113115
}
114116
}
115117

118+
impl crate::headers::Header for BasicAuth {
119+
fn header_name(&self) -> HeaderName {
120+
AUTHORIZATION
121+
}
122+
123+
fn header_value(&self) -> HeaderValue {
124+
self.value()
125+
}
126+
}
127+
116128
#[cfg(test)]
117129
mod test {
118130
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Apply the HTTP method if the ETag matches.
22
3+
use http::header::IF_MATCH;
4+
35
use crate::conditional::ETag;
46
use crate::headers::{HeaderName, HeaderValue, Headers, ToHeaderValues, IF_MATCH};
57

@@ -134,6 +136,15 @@ impl IfMatch {
134136
}
135137
}
136138

139+
impl crate::headers::Header for IfMatch {
140+
fn header_name(&self) -> HeaderName {
141+
IF_MATCH
142+
}
143+
fn header_value(&self) -> HeaderValue {
144+
self.value()
145+
}
146+
}
147+
137148
impl IntoIterator for IfMatch {
138149
type Item = ETag;
139150
type IntoIter = IntoIter;

src/conditional/if_modified_since.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use http::header::IF_MODIFIED_SINCE;
2+
13
use crate::headers::{HeaderName, HeaderValue, Headers, ToHeaderValues, IF_MODIFIED_SINCE};
24
use crate::utils::{fmt_http_date, parse_http_date};
35

@@ -93,6 +95,15 @@ impl ToHeaderValues for IfModifiedSince {
9395
}
9496
}
9597

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

0 commit comments

Comments
 (0)