diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-07-17 22:39:40 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-07-17 22:39:40 +0100 |
| commit | b50d93b8fc82aee86a3c0fde8ddacbcfff985ca4 (patch) | |
| tree | 0f9a4aa57dba8a287ba6006351459284e4feb78d /pkg/site | |
| parent | e1f6b6b8f3465b4819364efc497fea6d9ddad67e (diff) | |
Add status codes to site responses
Diffstat (limited to 'pkg/site')
| -rw-r--r-- | pkg/site/fs.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/pkg/site/fs.go b/pkg/site/fs.go index b4a941d..55abeac 100644 --- a/pkg/site/fs.go +++ b/pkg/site/fs.go @@ -22,6 +22,7 @@ func NewSiteFileServer(root http.FileSystem, siteConfig *config.SiteConfig) *Sit func (fs *SiteFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { if fs.siteConfig.Flags&config.FlagDisable != 0 { + w.WriteHeader(http.StatusForbidden) html.ForbiddenDisabledPage(fs.siteConfig.Host).Render(w) return } @@ -31,6 +32,7 @@ func (fs *SiteFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { file, err := fs.root.Open(path) if err != nil { if strings.HasSuffix(path, ".html") { + w.WriteHeader(http.StatusNotFound) html.NotFoundUrlPage(path, fs.siteConfig.Host).Render(w) return } @@ -38,6 +40,7 @@ func (fs *SiteFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { htmlPath := path + ".html" file, err = fs.root.Open(htmlPath) if err != nil { + w.WriteHeader(http.StatusNotFound) html.NotFoundUrlPage(path, fs.siteConfig.Host).Render(w) return } @@ -46,6 +49,7 @@ func (fs *SiteFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { info, err := file.Stat() if err != nil { + w.WriteHeader(http.StatusNotFound) html.NotFoundUrlPage(path, fs.siteConfig.Host).Render(w) return } @@ -54,6 +58,7 @@ func (fs *SiteFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { indexPath := filepath.Join(path, "index.html") if _, err := fs.root.Open(indexPath); os.IsNotExist(err) { if fs.siteConfig.Flags&config.FlagIndex == 0 { + w.WriteHeader(http.StatusNotFound) html.NotFoundUrlPage(path, fs.siteConfig.Host).Render(w) return } |
