12
12
//! }
13
13
//! ```
14
14
//!
15
- use std:: io;
16
-
17
- use std:: pin:: Pin ;
18
- use std:: task:: { Context , Poll } ;
15
+ use std:: {
16
+ convert:: TryInto ,
17
+ io,
18
+ pin:: Pin ,
19
+ task:: { Context , Poll } ,
20
+ } ;
19
21
20
22
use actix_web:: body:: BoxBody ;
21
23
use actix_web:: error:: PayloadError ;
@@ -45,11 +47,11 @@ impl FromRequest for DavRequest {
45
47
46
48
fn from_request ( req : & HttpRequest , payload : & mut dev:: Payload ) -> Self :: Future {
47
49
let mut builder = http:: Request :: builder ( )
48
- . method ( req. method ( ) . to_owned ( ) )
49
- . uri ( req. uri ( ) . to_owned ( ) )
50
- . version ( req. version ( ) . to_owned ( ) ) ;
50
+ . method ( req. method ( ) . as_ref ( ) )
51
+ . uri ( req. uri ( ) . to_string ( ) )
52
+ . version ( from_actix_http_version ( req. version ( ) ) ) ;
51
53
for ( name, value) in req. headers ( ) . iter ( ) {
52
- builder = builder. header ( name, value) ;
54
+ builder = builder. header ( name. as_str ( ) , value. as_ref ( ) ) ;
53
55
}
54
56
let path = req. match_info ( ) . unprocessed ( ) ;
55
57
let tail = req. match_info ( ) . unprocessed ( ) ;
@@ -82,29 +84,20 @@ impl http_body::Body for DavBody {
82
84
type Data = Bytes ;
83
85
type Error = io:: Error ;
84
86
85
- fn poll_data (
87
+ fn poll_frame (
86
88
self : Pin < & mut Self > ,
87
89
cx : & mut Context < ' _ > ,
88
- ) -> Poll < Option < Result < Self :: Data , Self :: Error > > > {
89
- let this = self . project ( ) ;
90
- match this. body . poll_next ( cx) {
91
- Poll :: Ready ( Some ( Ok ( data) ) ) => Poll :: Ready ( Some ( Ok ( data) ) ) ,
92
- Poll :: Ready ( Some ( Err ( err) ) ) => Poll :: Ready ( Some ( Err ( match err {
90
+ ) -> Poll < Option < Result < http_body:: Frame < Self :: Data > , Self :: Error > > > {
91
+ self . project ( )
92
+ . body
93
+ . poll_next ( cx)
94
+ . map_ok ( http_body:: Frame :: data)
95
+ . map_err ( |err| match err {
93
96
PayloadError :: Incomplete ( Some ( err) ) => err,
94
97
PayloadError :: Incomplete ( None ) => io:: ErrorKind :: BrokenPipe . into ( ) ,
95
98
PayloadError :: Io ( err) => err,
96
- other => io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "{:?}" , other) ) ,
97
- } ) ) ) ,
98
- Poll :: Ready ( None ) => Poll :: Ready ( None ) ,
99
- Poll :: Pending => Poll :: Pending ,
100
- }
101
- }
102
-
103
- fn poll_trailers (
104
- self : Pin < & mut Self > ,
105
- _cx : & mut Context ,
106
- ) -> Poll < Result < Option < http:: HeaderMap > , Self :: Error > > {
107
- Poll :: Ready ( Ok ( None ) )
99
+ err => io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "{err:?}" ) ) ,
100
+ } )
108
101
}
109
102
}
110
103
@@ -126,9 +119,9 @@ impl actix_web::Responder for DavResponse {
126
119
use crate :: body:: { Body , BodyType } ;
127
120
128
121
let ( parts, body) = self . 0 . into_parts ( ) ;
129
- let mut builder = HttpResponse :: build ( parts. status ) ;
122
+ let mut builder = HttpResponse :: build ( parts. status . as_u16 ( ) . try_into ( ) . unwrap ( ) ) ;
130
123
for ( name, value) in parts. headers . into_iter ( ) {
131
- builder. append_header ( ( name. unwrap ( ) , value) ) ;
124
+ builder. append_header ( ( name. unwrap ( ) . as_str ( ) , value. as_ref ( ) ) ) ;
132
125
}
133
126
// I noticed that actix-web returns an empty chunked body
134
127
// (\r\n0\r\n\r\n) and _no_ Transfer-Encoding header on
@@ -144,3 +137,16 @@ impl actix_web::Responder for DavResponse {
144
137
resp
145
138
}
146
139
}
140
+
141
+ /// Converts HTTP version from `actix_web` version of `http` crate while `actix_web` remains on old version.
142
+ /// https://github.com/actix/actix-web/issues/3384
143
+ fn from_actix_http_version ( v : actix_web:: http:: Version ) -> http:: Version {
144
+ match v {
145
+ actix_web:: http:: Version :: HTTP_3 => http:: Version :: HTTP_3 ,
146
+ actix_web:: http:: Version :: HTTP_2 => http:: Version :: HTTP_2 ,
147
+ actix_web:: http:: Version :: HTTP_11 => http:: Version :: HTTP_11 ,
148
+ actix_web:: http:: Version :: HTTP_10 => http:: Version :: HTTP_10 ,
149
+ actix_web:: http:: Version :: HTTP_09 => http:: Version :: HTTP_09 ,
150
+ v => unreachable ! ( "unexpected HTTP version {:?}" , v) ,
151
+ }
152
+ }
0 commit comments