Skip to content

Commit cc41f42

Browse files
committed
Add Date header if server does not send one
1 parent b713248 commit cc41f42

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/client.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use async_std::prelude::*;
55
use async_std::task::{Context, Poll};
66
use futures_core::ready;
77
use http_types::{
8-
headers::{HeaderName, HeaderValue, CONTENT_LENGTH, TRANSFER_ENCODING},
8+
headers::{HeaderName, HeaderValue, CONTENT_LENGTH, TRANSFER_ENCODING, DATE},
99
Body, Request, Response, StatusCode,
1010
};
1111

@@ -96,7 +96,7 @@ pub async fn encode(req: Request) -> Result<Encoder, std::io::Error> {
9696
Ok(Encoder::new(buf, req))
9797
}
9898

99-
/// Decode an HTTP respons on the client.
99+
/// Decode an HTTP response on the client.
100100
pub async fn decode<R>(reader: R) -> Result<Response, Exception>
101101
where
102102
R: Read + Unpin + Send + Sync + 'static,
@@ -142,6 +142,12 @@ where
142142
res.insert_header(name, value)?;
143143
}
144144

145+
if res.header(&DATE).is_none() {
146+
let date = format!("Date: {}\r\n", fmt_http_date(std::time::SystemTime::now()));
147+
let value = HeaderValue::from_str(std::str::from_utf8(date.as_bytes())?)?;
148+
res.insert_header(DATE, value)?;
149+
}
150+
145151
let content_length = res.header(&CONTENT_LENGTH);
146152
let transfer_encoding = res.header(&TRANSFER_ENCODING);
147153

0 commit comments

Comments
 (0)