mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
enable two way streaming for proxy. (#463)
This commit is contained in:
parent
e1b161bdfc
commit
f6f45c32fb
@ -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]
|
||||||
|
Loading…
Reference in New Issue
Block a user