diff --git a/src/bin/relay.rs b/src/bin/relay.rs index f98f44f..9084211 100644 --- a/src/bin/relay.rs +++ b/src/bin/relay.rs @@ -30,14 +30,14 @@ use tokio::{ }; use ptth::{ - http_serde::*, + http_serde, watcher::Watchers, }; enum Message { Meow, - HttpRequestResponse (RequestParts), - HttpResponseResponseStream (Body), + HttpRequestResponse (http_serde::RequestParts), + HttpResponseResponseStream ((http_serde::ResponseParts, Body)), } #[derive (Default)] @@ -94,13 +94,14 @@ async fn handle_http_response ( -> Response
{ println! ("Step 6"); - let body = req.into_body (); + let (parts, body) = req.into_parts (); + let resp_parts: http_serde::ResponseParts = rmp_serde::from_read_ref (&base64::decode (parts.headers.get ("X-PTTH-2LJYXWC4").unwrap ()).unwrap ()).unwrap (); { let mut watchers = state.watchers.lock ().await; println! ("Step 7"); - if ! watchers.wake_one (Message::HttpResponseResponseStream (body), &req_id) + if ! watchers.wake_one (Message::HttpResponseResponseStream ((resp_parts, body)), &req_id) { println! ("Step 8 (bad thing)"); status_reply (StatusCode::BAD_REQUEST, "A bad thing happened.\n") @@ -132,7 +133,7 @@ async fn handle_http_request ( .map (|(k, v)| (String::from (k.as_str ()), v.as_bytes ().to_vec ())) ); - RequestParts { + http_serde::RequestParts { id, method, uri, @@ -171,12 +172,17 @@ async fn handle_http_request ( }); match r.await { - Ok (Message::HttpResponseResponseStream (body)) => { + Ok (Message::HttpResponseResponseStream ((resp_parts, body))) => { println! ("Step 7"); - Response::builder () - .status (StatusCode::OK) - .header ("Accept-Ranges", "bytes") + let mut resp = Response::builder () + .status (hyper::StatusCode::from (resp_parts.status_code)); + + for (k, v) in resp_parts.headers.into_iter () { + resp = resp.header (&k, v); + } + + resp .body (body) .unwrap () }, diff --git a/src/bin/server.rs b/src/bin/server.rs index bc6d0c3..e529096 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -1,4 +1,5 @@ use std::{ + collections::*, convert::Infallible, error::Error, io::SeekFrom, @@ -26,7 +27,7 @@ use tokio::{ time::delay_for, }; -use ptth::http_serde::*; +use ptth::http_serde; fn parse_range_header (range_str: &str) -> (Option