From b11b301da5418c9613fa87719a1690906cb19f80 Mon Sep 17 00:00:00 2001 From: mpl Date: Wed, 23 Nov 2016 20:21:45 +0100 Subject: [PATCH] app/publisher: do not show all published nodes at root Also, trim request path suffix, so that /pics/foo/ is treated as /pics/foo Fixes #882 Change-Id: Ib943b1ab49dad3b463eea0157ad77d3df8515efa --- app/publisher/main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/publisher/main.go b/app/publisher/main.go index ae30e8a97..dd381fffb 100644 --- a/app/publisher/main.go +++ b/app/publisher/main.go @@ -595,7 +595,7 @@ func (ph *publishHandler) NewRequest(w http.ResponseWriter, r *http.Request) (*p ph: ph, rw: w, req: r, - suffix: suffix, + suffix: strings.TrimSuffix(suffix, "/"), base: base, subres: res, rootpn: ph.rootNode, @@ -606,7 +606,13 @@ func (ph *publishHandler) NewRequest(w http.ResponseWriter, r *http.Request) (*p func (pr *publishRequest) serveHTTP() { if !pr.rootpn.Valid() { - pr.rw.WriteHeader(404) + http.NotFound(pr.rw, pr.req) + return + } + + if pr.suffix == "" { + // Do not show everything at the root. + http.NotFound(pr.rw, pr.req) return } @@ -618,7 +624,7 @@ func (pr *publishRequest) serveHTTP() { if err := pr.findSubject(); err != nil { if err == os.ErrNotExist { - pr.rw.WriteHeader(404) + http.NotFound(pr.rw, pr.req) return } logf("Error looking up %s/%q: %v", pr.rootpn, pr.suffix, err)