@@ -4,7 +4,7 @@ use std::str::FromStr;
44
55use async_std:: io:: { BufReader , Read , Write } ;
66use async_std:: prelude:: * ;
7- use http_types:: headers:: { CONTENT_LENGTH , HOST , TRANSFER_ENCODING } ;
7+ use http_types:: headers:: { CONTENT_LENGTH , EXPECT , HOST , TRANSFER_ENCODING } ;
88use http_types:: { ensure, ensure_eq, format_err} ;
99use http_types:: { Body , Method , Request } ;
1010
@@ -128,14 +128,15 @@ fn set_url_and_port_from_host_header(req: &mut Request) -> http_types::Result<()
128128 Ok ( ( ) )
129129}
130130
131- async fn handle_100_continue < IO : Write + Unpin > (
132- req : & Request ,
133- io : & mut IO ,
134- ) -> http_types:: Result < ( ) > {
135- let expect_header_value = req. header ( "expect" ) . map ( |v| v. as_str ( ) ) ;
131+ const EXPECT_HEADER_VALUE : & str = "100-continue" ;
132+ const EXPECT_RESPONSE : & [ u8 ] = b"HTTP/1.1 100 Continue\r \n " ;
136133
137- if let Some ( "100-continue" ) = expect_header_value {
138- io. write_all ( "HTTP/1.1 100 Continue\r \n " . as_bytes ( ) ) . await ?;
134+ async fn handle_100_continue < IO > ( req : & Request , io : & mut IO ) -> http_types:: Result < ( ) >
135+ where
136+ IO : Write + Unpin ,
137+ {
138+ if let Some ( EXPECT_HEADER_VALUE ) = req. header ( EXPECT ) . map ( |h| h. as_str ( ) ) {
139+ io. write_all ( EXPECT_RESPONSE ) . await ?;
139140 }
140141
141142 Ok ( ( ) )
@@ -242,16 +243,8 @@ mod tests {
242243 }
243244
244245 fn request_with_host_header ( host : & str ) -> Request {
245- let mut req = Request :: new (
246- Method :: Get ,
247- url:: Url :: parse ( "http://_" )
248- . unwrap ( )
249- . join ( "/some/path" )
250- . unwrap ( ) ,
251- ) ;
252-
246+ let mut req = Request :: new ( Method :: Get , url:: Url :: parse ( "http://_/some/path" ) . unwrap ( ) ) ;
253247 req. insert_header ( HOST , host) ;
254-
255248 req
256249 }
257250}
0 commit comments