diff --git a/src/main.rs b/src/main.rs index 764cf59..364eff9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(toowned_clone_into)] + #[macro_use] extern crate anyhow; #[macro_use] extern crate log; #[macro_use] extern crate serde_derive; @@ -8,7 +10,7 @@ pub mod speak_proxy; use anyhow::Result as AnyhowResult; use crate::newrelic_logger::{NewRelicLogger, MaybeNewRelicTransaction}; use futures::future::{self, Future}; -use crate::speak_proxy::speak_proxy; +use crate::speak_proxy::{speak_proxy, speak_proxy_with_retry}; use hyper::{Method, StatusCode}; use hyper::header::HeaderValue; use hyper::http::header::HeaderName; @@ -135,7 +137,7 @@ pub async fn handle( match req.uri().path() { "/speak" => { let nr_transaction = newrelic_logger.web_transaction("/speak"); - let result = speak_proxy(client_ip, req, router, nr_transaction, "/speak").await; + let result = speak_proxy_with_retry(client_ip, req, router, nr_transaction, "/speak").await; match result { Ok(response) => { Ok(response) @@ -150,7 +152,7 @@ pub async fn handle( }, "/speak_spectrogram" => { let nr_transaction = newrelic_logger.web_transaction("/speak_spectrogram"); - let result = speak_proxy(client_ip, req, router, nr_transaction, "/speak_spectrogram").await; + let result = speak_proxy_with_retry(client_ip, req, router, nr_transaction, "/speak_spectrogram").await; match result { Ok(response) => { Ok(response) diff --git a/src/speak_proxy.rs b/src/speak_proxy.rs index 076600b..60700e1 100644 --- a/src/speak_proxy.rs +++ b/src/speak_proxy.rs @@ -35,30 +35,54 @@ struct RequestDetails { pub speaker: String, } -/*pub fn copy_request(request: &Request
) -> Request { - let body = hyper::body::to_bytes(request.body()); +pub fn copy_request(request: &Request) -> Request { + let mut cloned = Request::builder() + .body(Body::from("")) + .unwrap(); + + request.clone_into(&mut &cloned); + + + /*let body_bytes = hyper::body::to_bytes(request.body()); + let body = Body::from(body_bytes); + Body::from(request.body()); + Request::builder() .uri(request.uri()) .method(request.method()) - .unwrap() -}*/ + .body(body) + .unwrap()*/ -/*pub fn speak_proxy_with_retry( + cloned +} + +pub async fn speak_proxy_with_retry( + ip_addr: IpAddr, req: Request, - remote_addr: SocketAddr, router: Arc