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
This commit is contained in:
mpl 2016-11-23 20:21:45 +01:00
parent d7a3333c0a
commit b11b301da5
1 changed files with 9 additions and 3 deletions

View File

@ -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)