@@ -67,6 +67,8 @@ extern crate maplit;
67
67
pub use http:: { self , Response } ;
68
68
use lambda_runtime:: LambdaEvent ;
69
69
pub use lambda_runtime:: { self , service_fn, tower, Context , Error , Service } ;
70
+ use request:: RequestFuture ;
71
+ use response:: ResponseFuture ;
70
72
71
73
pub mod ext;
72
74
pub mod request;
@@ -91,9 +93,9 @@ pub type Request = http::Request<Body>;
91
93
///
92
94
/// This is used by the `Adapter` wrapper and is completely internal to the `lambda_http::run` function.
93
95
#[ doc( hidden) ]
94
- pub struct TransformResponse < ' a , R , E > {
95
- request_origin : RequestOrigin ,
96
- fut : Pin < Box < dyn Future < Output = Result < R , E > > + ' a > > ,
96
+ pub enum TransformResponse < ' a , R , E > {
97
+ Request ( RequestOrigin , RequestFuture < ' a , R , E > ) ,
98
+ Response ( RequestOrigin , ResponseFuture ) ,
97
99
}
98
100
99
101
impl < ' a , R , E > Future for TransformResponse < ' a , R , E >
@@ -103,11 +105,19 @@ where
103
105
type Output = Result < LambdaResponse , E > ;
104
106
105
107
fn poll ( mut self : Pin < & mut Self > , cx : & mut TaskContext ) -> Poll < Self :: Output > {
106
- match self . fut . as_mut ( ) . poll ( cx) {
107
- Poll :: Ready ( result) => Poll :: Ready (
108
- result. map ( |resp| LambdaResponse :: from_response ( & self . request_origin , resp. into_response ( ) ) ) ,
109
- ) ,
110
- Poll :: Pending => Poll :: Pending ,
108
+ match * self {
109
+ TransformResponse :: Request ( ref mut origin, ref mut request) => match request. as_mut ( ) . poll ( cx) {
110
+ Poll :: Ready ( Ok ( resp) ) => {
111
+ * self = TransformResponse :: Response ( origin. clone ( ) , resp. into_response ( ) ) ;
112
+ self . poll ( cx)
113
+ }
114
+ Poll :: Ready ( Err ( err) ) => Poll :: Ready ( Err ( err) ) ,
115
+ Poll :: Pending => Poll :: Pending ,
116
+ } ,
117
+ TransformResponse :: Response ( ref mut origin, ref mut response) => match response. as_mut ( ) . poll ( cx) {
118
+ Poll :: Ready ( resp) => Poll :: Ready ( Ok ( LambdaResponse :: from_response ( origin, resp) ) ) ,
119
+ Poll :: Pending => Poll :: Pending ,
120
+ } ,
111
121
}
112
122
}
113
123
}
@@ -153,7 +163,8 @@ where
153
163
let request_origin = req. payload . request_origin ( ) ;
154
164
let event: Request = req. payload . into ( ) ;
155
165
let fut = Box :: pin ( self . service . call ( event. with_lambda_context ( req. context ) ) ) ;
156
- TransformResponse { request_origin, fut }
166
+
167
+ TransformResponse :: Request ( request_origin, fut)
157
168
}
158
169
}
159
170
0 commit comments