From c89569aa8ed28b0884e9a89f4400380d2fd75161 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 29 Jun 2020 15:21:20 -0400 Subject: [PATCH] Proxying works! --- src/main.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index fffc16a..dbaf59b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ impl ProxyConfigs { } } -#[derive(Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug)] pub struct SpeakRequest { /// Slug for the speaker speaker: String, @@ -156,12 +156,25 @@ fn main() -> AnyhowResult<()> { } else if req.uri().path().eq("/speak_spectrogram") { Box::new(req.into_body().concat2().map(move |b| { // Builds a BoxedFut to return - serde_json::from_slice::(b.as_ref()) + let request_bytes = b.as_ref(); + serde_json::from_slice::(request_bytes) .unwrap() }).and_then(move |speak_request: SpeakRequest| { let remote_addr3 = remote_addr2.clone(); - let new_req = Request::new(Body::empty()); - hyper_reverse_proxy::call(remote_addr3.ip(), "http://127.0.0.1:12345/speak_request", new_req) + + let request_json = serde_json::to_string(&speak_request) + .unwrap(); + + let new_req = Request::builder() + .method(Method::POST) + .uri("/speak_spectrogram") + .header("X-Forwarded-For", "https://localhost:12345/frontend/index.html") + .header("Origin", "http://localhost:12345") + .header("Referer", "http://localhost:12345/frontend/index.html") + .body(Body::from(request_json)) + .unwrap(); + + hyper_reverse_proxy::call(remote_addr3.ip(), "http://127.0.0.1:12345", new_req) })) //Box::new(boxed.then( |b : Result, Error> | {