@@ -232,7 +232,7 @@ impl HttpSession {
232232 }
233233
234234 /// Write response body to the client. See [Self::write_response_header] for how to use `end`.
235- pub fn write_body ( & mut self , data : Bytes , end : bool ) -> Result < ( ) > {
235+ pub async fn write_body ( & mut self , data : Bytes , end : bool ) -> Result < ( ) > {
236236 if self . ended {
237237 // NOTE: in h1, we also track to see if content-length matches the data
238238 // We have not tracked that in h2
@@ -246,11 +246,9 @@ impl HttpSession {
246246 ) ) ;
247247 } ;
248248 let data_len = data. len ( ) ;
249- writer. reserve_capacity ( data_len) ;
250- writer. send_data ( data, end) . or_err (
251- ErrorType :: WriteError ,
252- "while writing h2 response body to downstream" ,
253- ) ?;
249+ super :: write_body ( writer, data, end)
250+ . await
251+ . map_err ( |e| e. into_down ( ) ) ?;
254252 self . body_sent += data_len;
255253 self . ended = self . ended || end;
256254 Ok ( ( ) )
@@ -308,7 +306,7 @@ impl HttpSession {
308306 Ok ( ( ) )
309307 }
310308
311- pub fn response_duplex_vec ( & mut self , tasks : Vec < HttpTask > ) -> Result < bool > {
309+ pub async fn response_duplex_vec ( & mut self , tasks : Vec < HttpTask > ) -> Result < bool > {
312310 let mut end_stream = false ;
313311 for task in tasks. into_iter ( ) {
314312 end_stream = match task {
@@ -320,7 +318,7 @@ impl HttpSession {
320318 HttpTask :: Body ( data, end) => match data {
321319 Some ( d) => {
322320 if !d. is_empty ( ) {
323- self . write_body ( d, end) . map_err ( |e| e. into_down ( ) ) ?;
321+ self . write_body ( d, end) . await . map_err ( |e| e. into_down ( ) ) ?;
324322 }
325323 end
326324 }
@@ -567,7 +565,7 @@ mod test {
567565 }
568566
569567 // end: false here to verify finish() closes the stream nicely
570- http. write_body ( server_body. into ( ) , false ) . unwrap ( ) ;
568+ http. write_body ( server_body. into ( ) , false ) . await . unwrap ( ) ;
571569 assert_eq ! ( http. body_bytes_sent( ) , 16 ) ;
572570
573571 http. write_trailers ( trailers) . unwrap ( ) ;
@@ -639,7 +637,7 @@ mod test {
639637 . write_response_header( response_header. clone( ) , false )
640638 . is_ok( ) ) ;
641639
642- http. write_body ( server_body. into ( ) , false ) . unwrap ( ) ;
640+ http. write_body ( server_body. into ( ) , false ) . await . unwrap ( ) ;
643641 assert_eq ! ( http. body_bytes_sent( ) , 16 ) ;
644642
645643 // 3. Waiting for the reset from the client
@@ -711,7 +709,7 @@ mod test {
711709 . write_response_header( response_header. clone( ) , false )
712710 . is_ok( ) ) ;
713711
714- http. write_body ( server_body. into ( ) , false ) . unwrap ( ) ;
712+ http. write_body ( server_body. into ( ) , false ) . await . unwrap ( ) ;
715713 assert_eq ! ( http. body_bytes_sent( ) , 16 ) ;
716714
717715 // 3. Waiting for the client to close stream.
0 commit comments