Skip to content

Commit

Permalink
wip: cont on http interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cablehead committed Jun 3, 2024
1 parent d103aef commit d895ab0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,29 @@ async fn handle(
Err("event stream ended")
}

let response = wait_for_response(&store, frame.id).await.unwrap();
let meta = wait_for_response(&store, frame.id).await.unwrap();

eprintln!("RESPONSE {:?}", meta);

let res = hyper::Response::builder();
let mut res = res.status(meta.status.unwrap_or(200));
{
let res_headers = res.headers_mut().unwrap();
if let Some(headers) = meta.headers {
for (key, value) in headers {
res_headers.insert(
http::header::HeaderName::from_bytes(key.as_bytes()).unwrap(),
http::header::HeaderValue::from_bytes(value.as_bytes()).unwrap(),
);
}
}

eprintln!("RESPONSE {:?}", response);
if !res_headers.contains_key("content-type") {
res_headers.insert("content-type", "text/plain".parse().unwrap());
}
}

Ok(hyper::Response::builder()
.status(response.status.unwrap_or(200))
.header("Content-Type", "application/json")
.body(full(serde_json::to_string(&frame).unwrap()))?)
Ok(res.body(full(serde_json::to_string(&frame).unwrap()))?)
}

pub async fn serve(
Expand Down

0 comments on commit d895ab0

Please sign in to comment.