From 1f0340b43675dd90009c5f67b70ef6fa224ee606 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Sun, 1 May 2016 21:53:20 -0700 Subject: [PATCH] website: simplify docHandler don't strip the "/doc" prefix, which simplifies some of the file handling logic. Also add a test case for the /docs/ => /doc/ redirect. Change-Id: I96c60bc031daaeff7f78ca854b60bdc542913b3d --- website/camweb.go | 6 +++--- website/camweb_test.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/website/camweb.go b/website/camweb.go index a0e36a90e..62b703f26 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -250,7 +250,7 @@ func mainHandler(rw http.ResponseWriter, req *http.Request) { } func docHandler(rw http.ResponseWriter, req *http.Request) { - findAndServeFile(rw, req, filepath.Join(filepath.Dir(*root), "doc")) + findAndServeFile(rw, req, filepath.Dir(*root)) } // modtime is the modification time of the resource to be served, or IsZero(). @@ -307,7 +307,7 @@ func findAndServeFile(rw http.ResponseWriter, req *http.Request, root string) { // the URL with a trailing slash so relative links within that // directory work. if fi.IsDir() && !strings.HasSuffix(req.URL.Path, "/") { - http.Redirect(rw, req, "/doc"+req.URL.Path+"/", http.StatusFound) + http.Redirect(rw, req, req.URL.Path+"/", http.StatusFound) return } @@ -770,7 +770,7 @@ func main() { mux.Handle("/lists", redirTo("/community")) mux.HandleFunc("/contributors", contribHandler()) - mux.Handle("/doc/", http.StripPrefix("/doc", http.HandlerFunc(docHandler))) + mux.HandleFunc("/doc/", docHandler) mux.HandleFunc("/", mainHandler) if buildbotHost != "" && buildbotBackend != "" { diff --git a/website/camweb_test.go b/website/camweb_test.go index 5bbc1a199..f596bfb8f 100644 --- a/website/camweb_test.go +++ b/website/camweb_test.go @@ -30,6 +30,7 @@ func TestRedirect(t *testing.T) { {"/gw/502aff1fd522c454e39a3723b596aca43d206d4e", "https://camlistore.googlesource.com/camlistore/+/502aff1fd522c454e39a3723b596aca43d206d4e"}, {"/gw/doc", "https://camlistore.googlesource.com/camlistore/+/master/doc"}, {"/code/?p=camlistore.git;a=commit;h=b0d2a8f0e5f27bbfc025a96ec3c7896b42d198ed", "https://camlistore.googlesource.com/camlistore/+/b0d2a8f0e5f27bbfc025a96ec3c7896b42d198ed"}, + {"/docs/schema/", "/doc/schema/"}, } for _, tt := range tests { u, err := url.ParseRequestURI(tt.in)