chiark / gitweb /
own http body type
[hippotat.git] / server / sweb.rs
index 157261abe7864c2541f16439b837c73401f29914..0176e46afba58b28d0add5581b7b073d1e0b7fb5 100644 (file)
@@ -19,6 +19,7 @@ pub struct WebRequest {
   pub reply_to: oneshot::Sender<WebResponse>,
   pub warnings: Warnings,
   pub conn: Arc<String>,
+  pub may_route: MayRoute,
 }
 
 /// Reply from client task to hyper worker pool task
@@ -29,15 +30,16 @@ pub struct WebResponse {
   pub data: Result<WebResponseData, AE>,
 }
 
-pub type WebResponseData = Vec<u8>;
+pub type WebResponseData = FrameQueueBuf;
+pub type WebResponseBody = BufBody<FrameQueueBuf>;
 
 pub async fn handle(
   conn: Arc<String>,
   global: Arc<Global>,
   req: hyper::Request<hyper::Body>
-) -> Result<hyper::Response<hyper::Body>, hyper::http::Error> {
+) -> Result<hyper::Response<WebResponseBody>, hyper::http::Error> {
   if req.method() == Method::GET {
-    let mut resp = hyper::Response::new(hyper::Body::from("hippotat\r\n"));
+    let mut resp = hyper::Response::new(BufBody::display("hippotat\r\n"));
     resp.headers_mut().insert(
       "Content-Type",
       "text/plain; charset=US-ASCII".try_into().unwrap()
@@ -148,7 +150,7 @@ pub async fn handle(
     //dbg!(DumpHex(hmac_got), hmac_ok, client_exists);
     if ! bool::from(hmac_ok & client_exists) {
       debug!("{} rejected client {}", &conn, &client_name);
-      let body = hyper::Body::from("Not authorised\r\n");
+      let body = BufBody::display("Not authorised\r\n");
       return Ok(
         hyper::Response::builder()
           .status(hyper::StatusCode::FORBIDDEN)
@@ -188,6 +190,7 @@ pub async fn handle(
       warnings: mem::take(&mut warnings),
       reply_to,
       conn: conn.clone(),
+      may_route: MayRoute::came_from_outside_hippotatd(),
     };
 
     client.web.try_send(wreq)
@@ -206,7 +209,7 @@ pub async fn handle(
              &warnings.warnings);
     }
 
-    let data = hyper::Body::from(data);
+    let data = BufBody::new(data);
     Ok::<_,AE>(
       hyper::Response::builder()
         .header("Content-Type", r#"application/octet-stream"#)
@@ -221,6 +224,6 @@ pub async fn handle(
     hyper::Response::builder()
       .status(hyper::StatusCode::BAD_REQUEST)
       .header("Content-Type", r#"text/plain; charset="utf-8""#)
-      .body(errmsg.into())
+      .body(BufBody::display(errmsg))
   })
 }