@@ -4,7 +4,7 @@ use std::str::FromStr;
4
4
5
5
use async_std:: io:: { BufReader , Read , Write } ;
6
6
use async_std:: prelude:: * ;
7
- use http_types:: headers:: { CONTENT_LENGTH , HOST , TRANSFER_ENCODING } ;
7
+ use http_types:: headers:: { CONTENT_LENGTH , EXPECT , HOST , TRANSFER_ENCODING } ;
8
8
use http_types:: { ensure, ensure_eq, format_err} ;
9
9
use http_types:: { Body , Method , Request } ;
10
10
@@ -128,14 +128,15 @@ fn set_url_and_port_from_host_header(req: &mut Request) -> http_types::Result<()
128
128
Ok ( ( ) )
129
129
}
130
130
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 " ;
136
133
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 ?;
139
140
}
140
141
141
142
Ok ( ( ) )
@@ -242,16 +243,8 @@ mod tests {
242
243
}
243
244
244
245
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 ( ) ) ;
253
247
req. insert_header ( HOST , host) ;
254
-
255
248
req
256
249
}
257
250
}
0 commit comments