about summary refs log tree commit diff
path: root/web/bubblegum
diff options
context:
space:
mode:
Diffstat (limited to 'web/bubblegum')
-rw-r--r--web/bubblegum/default.nix17
-rw-r--r--web/bubblegum/examples/blog.nix8
2 files changed, 16 insertions, 9 deletions
diff --git a/web/bubblegum/default.nix b/web/bubblegum/default.nix
index 393ac75d4803..aecc701886b5 100644
--- a/web/bubblegum/default.nix
+++ b/web/bubblegum/default.nix
@@ -89,12 +89,12 @@ let
 
      See the [README](./README.md) for an example.
 
-    Type: string -> attrs string -> string -> string
+    Type: either int string -> attrs string -> string -> string
   */
   respond =
-    # response status as the textual representation in the
-    # HTTP protocol. See `statusCodes` for a list of valid
-    # options.
+    # response status as an integer (status code) or its
+    # textual representation in the HTTP protocol.
+    # See `statusCodes` for a list of valid options.
     statusArg:
     # headers as an attribute set of strings
     headers:
@@ -102,7 +102,14 @@ let
     bodyArg:
     let
       status =
-        if builtins.isString statusArg then {
+        if builtins.isInt statusArg
+        then {
+          code = statusArg;
+          line = lib.findFirst
+            (line: statusCodes."${line}" == statusArg)
+            null
+            (builtins.attrNames statusCodes);
+        } else if builtins.isString statusArg then {
           code = statusCodes."${statusArg}" or null;
           line = statusArg;
         } else {
diff --git a/web/bubblegum/examples/blog.nix b/web/bubblegum/examples/blog.nix
index f79ab0627e88..213fbb7d19ba 100644
--- a/web/bubblegum/examples/blog.nix
+++ b/web/bubblegum/examples/blog.nix
@@ -108,24 +108,24 @@ let
     if pathInfo == "/"
     then {
       title = "blog";
-      status = "OK";
+      status = 200;
       inner = index posts;
     }
     else if !(validatePathInfo pathInfo)
     then {
       title = "Bad Request";
-      status = "Bad Request";
+      status = 400;
       inner = "No slashes in post names 😡";
     }
     # CGI should already url.decode for us
     else if builtins.pathExists (blogdir + "/" + pathInfo)
     then rec {
       title = parseTitle pathInfo;
-      status = "OK";
+      status = 200;
       inner = post title pathInfo;
     } else {
       title = "Not Found";
-      status = "Not Found";
+      status = 404;
       inner = "<h1>404 — not found</h1>";
     };
 in