@@ -11,11 +11,10 @@ use async_std::prelude::*;
1111use async_std:: task:: { Context , Poll } ;
1212use futures_core:: ready;
1313use http_types:: headers:: { HeaderName , HeaderValue , CONTENT_LENGTH , TRANSFER_ENCODING } ;
14- use http_types:: { Body , Method , Request , Response } ;
14+ use http_types:: { Body , Method , Request , Response , StatusCode , Error , ErrorKind } ;
1515
1616use crate :: chunked:: ChunkedDecoder ;
1717use crate :: date:: fmt_http_date;
18- use crate :: error:: HttpError ;
1918use crate :: { Exception , MAX_HEADERS } ;
2019
2120const CR : u8 = b'\r' ;
@@ -24,7 +23,7 @@ const LF: u8 = b'\n';
2423/// Parse an incoming HTTP connection.
2524///
2625/// Supports `KeepAlive` requests by default.
27- pub async fn accept < RW , F , Fut > ( addr : & str , mut io : RW , endpoint : F ) -> Result < ( ) , Exception >
26+ pub async fn accept < RW , F , Fut > ( addr : & str , mut io : RW , endpoint : F ) -> http_types :: Result < ( ) >
2827where
2928 RW : Read + Write + Clone + Send + Sync + Unpin + ' static ,
3029 F : Fn ( Request ) -> Fut ,
5655 req = match timeout ( timeout_duration, decode ( addr, io. clone ( ) ) ) . await {
5756 Ok ( Ok ( Some ( r) ) ) => r,
5857 Ok ( Ok ( None ) ) | Err ( TimeoutError { .. } ) => break , /* EOF or timeout */
59- Ok ( Err ( e) ) => return Err ( e) ,
58+ Ok ( Err ( e) ) => return Err ( e) . into ( ) ,
6059 } ;
6160 // Loop back with the new request and stream and start again
6261 }
@@ -336,7 +335,7 @@ impl Read for Encoder {
336335const HTTP_1_1_VERSION : u8 = 1 ;
337336
338337/// Decode an HTTP request on the server.
339- async fn decode < R > ( addr : & str , reader : R ) -> Result < Option < Request > , Exception >
338+ async fn decode < R > ( addr : & str , reader : R ) -> Result < Option < Request > , Error >
340339where
341340 R : Read + Unpin + Send + Sync + ' static ,
342341{
@@ -388,7 +387,7 @@ where
388387
389388 if content_length. is_some ( ) && transfer_encoding. is_some ( ) {
390389 // This is always an error.
391- return Err ( HttpError :: UnexpectedContentLengthHeader . into ( ) ) ;
390+ return Err ( Error :: new ( ErrorKind :: InvalidData , "Unexpected Content-Length header" , StatusCode :: BadRequest ) ) ;
392391 }
393392
394393 // Check for Transfer-Encoding
0 commit comments