aboutsummaryrefslogtreecommitdiff
path: root/lib/http/fs_handler.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-06 23:00:07 +0700
committerShulhan <ms@kilabit.info>2026-01-06 23:05:47 +0700
commite91954b5a65847970903e0d8294e54d918c8bc0b (patch)
tree95d971ce7c35fdc1d586e52ba53189ca2d88d93a /lib/http/fs_handler.go
parentf9567f0d4fc5cf6d0e1cea2d22289250c6b1cb2b (diff)
downloadpakakeh.go-e91954b5a65847970903e0d8294e54d918c8bc0b.tar.xz
lib/http: add second return value, statusCode, to FSHandler
Non-zero status code indicates that the function already response to the request, and the server will return immediately. Zero status code indicates that the function did not process the request, it is up to server to process the returned node `out`.
Diffstat (limited to 'lib/http/fs_handler.go')
-rw-r--r--lib/http/fs_handler.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/http/fs_handler.go b/lib/http/fs_handler.go
index b88c13b4..7dfca198 100644
--- a/lib/http/fs_handler.go
+++ b/lib/http/fs_handler.go
@@ -15,11 +15,16 @@ import (
// The node parameter contains the requested file inside the memfs or nil
// if the file does not exist.
//
-// If the handler return non-nil [*memfs.Node], server will continue
-// processing the node, writing the [memfs.Node] content type, body, and so
-// on.
+// This function return two values: the node `out` that is used to process the
+// request and response; and the HTTP status code `statusCode` returned in
+// response.
//
-// If the handler return nil, server stop processing the node and return
-// immediately, which means the function should have already handle writing
-// the header, status code, and/or body.
-type FSHandler func(node *memfs.Node, res http.ResponseWriter, req *http.Request) (out *memfs.Node)
+// Non-zero status code indicates that the function already response
+// to the request, and the server will return immediately.
+//
+// Zero status code indicates that the function did not process the request,
+// it is up to server to process the returned node `out`.
+// The returned node `out` may be the same as `node`, modified, of completely
+// new.
+type FSHandler func(node *memfs.Node, res http.ResponseWriter, req *http.Request) (
+ out *memfs.Node, statusCode int)