@@ -5,14 +5,15 @@ use async_std::prelude::*;
55use async_std:: task:: { Context , Poll } ;
66use futures_core:: ready;
77use http_types:: {
8- headers:: { HeaderName , HeaderValue , CONTENT_LENGTH , TRANSFER_ENCODING } ,
8+ headers:: { HeaderName , HeaderValue , CONTENT_LENGTH , DATE , TRANSFER_ENCODING } ,
99 Body , Request , Response , StatusCode ,
1010} ;
1111
1212use std:: pin:: Pin ;
1313use std:: str:: FromStr ;
1414
1515use crate :: chunked:: ChunkedDecoder ;
16+ use crate :: date:: fmt_http_date;
1617use crate :: error:: HttpError ;
1718use crate :: { Exception , MAX_HEADERS } ;
1819
@@ -77,6 +78,12 @@ pub async fn encode(req: Request) -> Result<Encoder, std::io::Error> {
7778 // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding
7879 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer
7980 }
81+
82+ let date = fmt_http_date ( std:: time:: SystemTime :: now ( ) ) ;
83+ buf. write_all ( b"date: " ) . await ?;
84+ buf. write_all ( date. as_bytes ( ) ) . await ?;
85+ buf. write_all ( b"\r \n " ) . await ?;
86+
8087 for ( header, values) in req. iter ( ) {
8188 for value in values. iter ( ) {
8289 let val = format ! ( "{}: {}\r \n " , header, value) ;
@@ -90,7 +97,7 @@ pub async fn encode(req: Request) -> Result<Encoder, std::io::Error> {
9097 Ok ( Encoder :: new ( buf, req) )
9198}
9299
93- /// Decode an HTTP respons on the client.
100+ /// Decode an HTTP response on the client.
94101pub async fn decode < R > ( reader : R ) -> Result < Response , Exception >
95102where
96103 R : Read + Unpin + Send + Sync + ' static ,
@@ -136,6 +143,11 @@ where
136143 res. insert_header ( name, value) ?;
137144 }
138145
146+ if res. header ( & DATE ) . is_none ( ) {
147+ let date = fmt_http_date ( std:: time:: SystemTime :: now ( ) ) ;
148+ res. insert_header ( DATE , & format ! ( "date: {}\r \n " , date) [ ..] ) ?;
149+ }
150+
139151 let content_length = res. header ( & CONTENT_LENGTH ) ;
140152 let transfer_encoding = res. header ( & TRANSFER_ENCODING ) ;
141153
0 commit comments