chiark / gitweb /
own http body type
[hippotat.git] / server / sweb.rs
index d4e825e0886f60b093cf99e455379cc38b6a6153..0176e46afba58b28d0add5581b7b073d1e0b7fb5 100644 (file)
@@ -30,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()
@@ -149,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)
@@ -208,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"#)
@@ -223,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))
   })
 }