diff --git a/.gitignore b/.gitignore index 1521c8b..3f832a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ dist +cmd/gemini diff --git a/filesystem.go b/filesystem.go index f7e01c5..33b90c9 100644 --- a/filesystem.go +++ b/filesystem.go @@ -92,6 +92,10 @@ func FileSystemHandler(fs FileSystem) Handler { } f, err := fs.Open(r.URL.Path) if err != nil { + if os.IsNotExist(err) { + NotFoundHandler().ServeGemini(w, r) + return + } log.Warn("FileSystemHandler: file open failed", log.String("reason", err.Error()), log.String("path", r.URL.Path), log.String("url", r.URL.String())) w.SetHeader(CodeTemporaryFailure, "file open failed") return diff --git a/filesystem_test.go b/filesystem_test.go index bd00306..746496e 100644 --- a/filesystem_test.go +++ b/filesystem_test.go @@ -37,6 +37,15 @@ func TestFileSystemHandler(t *testing.T) { expectedHeader: geminiSuccessHeader, expectedBody: "# /tests/a/index.gmi\n", }, + { + name: "non-existent files return a 51 status code", + url: "/a/non-existent.gmi", + expectedHeader: Header{ + Code: CodeNotFound, + Meta: "", + }, + expectedBody: "", + }, { name: "a slash prefix is added if missing", url: "a/index.gmi", diff --git a/server_test.go b/server_test.go index e18b553..cf3a2ec 100644 --- a/server_test.go +++ b/server_test.go @@ -149,7 +149,7 @@ func TestServer(t *testing.T) { expectedBodyErr: nil, }, { - name: "panics in handlers return a GCI error", + name: "panics in handlers return a CGI error", request: "gemini://sensible\r\n", handler: func(w ResponseWriter, r *Request) { panic("oops")