1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

enable two way streaming for proxy. (#463)

This commit is contained in:
fakeshadow 2021-11-12 21:30:48 +08:00 committed by GitHub
parent e1b161bdfc
commit f6f45c32fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ use url::Url;
async fn forward( async fn forward(
req: HttpRequest, req: HttpRequest,
body: web::Bytes, payload: web::Payload,
url: web::Data<Url>, url: web::Data<Url>,
client: web::Data<Client>, client: web::Data<Client>,
) -> Result<HttpResponse, Error> { ) -> Result<HttpResponse, Error> {
@ -26,7 +26,10 @@ async fn forward(
forwarded_req forwarded_req
}; };
let mut res = forwarded_req.send_body(body).await.map_err(Error::from)?; let res = forwarded_req
.send_stream(payload)
.await
.map_err(Error::from)?;
let mut client_resp = HttpResponse::build(res.status()); let mut client_resp = HttpResponse::build(res.status());
// Remove `Connection` as per // Remove `Connection` as per
@ -37,7 +40,7 @@ async fn forward(
client_resp.header(header_name.clone(), header_value.clone()); client_resp.header(header_name.clone(), header_value.clone());
} }
Ok(client_resp.body(res.body().await?)) Ok(client_resp.streaming(res))
} }
#[actix_web::main] #[actix_web::main]