1
1
//! Process HTTP connections on the server.
2
2
3
+ use std:: error:: Error ;
4
+ use std:: fmt;
5
+ use std:: pin:: Pin ;
6
+ use std:: str:: FromStr ;
7
+ use std:: time:: Duration ;
8
+
3
9
use async_std:: future:: { timeout, Future , TimeoutError } ;
4
10
use async_std:: io:: { self , BufReader } ;
5
11
use async_std:: io:: { Read , Write } ;
@@ -8,23 +14,37 @@ use async_std::task::{Context, Poll};
8
14
use futures_core:: ready;
9
15
use http_types:: headers:: { HeaderName , HeaderValue , CONTENT_LENGTH , TRANSFER_ENCODING } ;
10
16
use http_types:: { Body , Method , Request , Response } ;
11
- use std:: str:: FromStr ;
12
- use std:: time:: Duration ;
13
- use thiserror:: Error ;
14
-
15
- use std:: pin:: Pin ;
16
17
17
18
use crate :: chunked:: ChunkedDecoder ;
18
19
use crate :: date:: fmt_http_date;
19
20
use crate :: { Exception , MAX_HEADERS } ;
20
21
21
22
/// Errors when handling incoming requests.
22
- #[ derive( Debug , Error ) ]
23
+ #[ derive( Debug ) ]
23
24
pub enum HttpError {
24
- #[ error( "unexpected content-length header" ) ]
25
25
UnexpectedContentLengthHeader ,
26
26
}
27
27
28
+ impl fmt:: Display for HttpError {
29
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
30
+ match self {
31
+ HttpError :: UnexpectedContentLengthHeader => write ! ( f, "{}" , self . description( ) ) ,
32
+ }
33
+ }
34
+ }
35
+
36
+ impl Error for HttpError {
37
+ fn description ( & self ) -> & str {
38
+ match self {
39
+ HttpError :: UnexpectedContentLengthHeader => "unexpected content-length header" ,
40
+ }
41
+ }
42
+
43
+ fn cause ( & self ) -> Option < & dyn Error > {
44
+ None
45
+ }
46
+ }
47
+
28
48
/// Parse an incoming HTTP connection.
29
49
///
30
50
/// Supports `KeepAlive` requests by default.
0 commit comments