mirror of https://github.com/perkeep/perkeep.git
website: more redirects to the issues tracker
http://camlistore.org/issue/243 Change-Id: I25424ae5e69f602e8a8bb8d69954f37f28b8f687
This commit is contained in:
parent
7c3a7bd30a
commit
14fdd3f066
|
@ -199,6 +199,11 @@ func mainHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dest, ok := issueRedirect(req.URL.Path); ok {
|
||||||
|
http.Redirect(rw, req, dest, http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
relPath := req.URL.Path[1:] // serveFile URL paths start with '/'
|
relPath := req.URL.Path[1:] // serveFile URL paths start with '/'
|
||||||
if strings.Contains(relPath, "..") {
|
if strings.Contains(relPath, "..") {
|
||||||
return
|
return
|
||||||
|
@ -336,7 +341,6 @@ func main() {
|
||||||
mux.HandleFunc("/r/", gerritRedirect)
|
mux.HandleFunc("/r/", gerritRedirect)
|
||||||
mux.HandleFunc("/debugz/ip", ipHandler)
|
mux.HandleFunc("/debugz/ip", ipHandler)
|
||||||
|
|
||||||
mux.HandleFunc("/issue/", issueRedirect)
|
|
||||||
mux.HandleFunc("/", mainHandler)
|
mux.HandleFunc("/", mainHandler)
|
||||||
|
|
||||||
if *buildbotHost != "" && *buildbotBackend != "" {
|
if *buildbotHost != "" && *buildbotBackend != "" {
|
||||||
|
@ -384,15 +388,22 @@ func main() {
|
||||||
log.Fatalf("Serve error: %v", <-errc)
|
log.Fatalf("Serve error: %v", <-errc)
|
||||||
}
|
}
|
||||||
|
|
||||||
var issueNum = regexp.MustCompile(`^/issue/(\d+)$`)
|
var issueNum = regexp.MustCompile(`^/(?:issue(?:s)?|bugs)(/\d*)?$`)
|
||||||
|
|
||||||
func issueRedirect(w http.ResponseWriter, r *http.Request) {
|
// issueRedirect returns whether the request should be redirected to the
|
||||||
m := issueNum.FindStringSubmatch(r.URL.Path)
|
// issues tracker, and the url for that redirection if yes, the empty
|
||||||
|
// string otherwise.
|
||||||
|
func issueRedirect(urlPath string) (string, bool) {
|
||||||
|
m := issueNum.FindStringSubmatch(urlPath)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
http.Error(w, "Bad request", 400)
|
return "", false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, "https://code.google.com/p/camlistore/issues/detail?id="+m[1], http.StatusFound)
|
issueNumber := strings.TrimPrefix(m[1], "/")
|
||||||
|
suffix := "list"
|
||||||
|
if issueNumber != "" {
|
||||||
|
suffix = "detail?id=" + issueNumber
|
||||||
|
}
|
||||||
|
return "https://code.google.com/p/camlistore/issues/" + suffix, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func gerritRedirect(w http.ResponseWriter, r *http.Request) {
|
func gerritRedirect(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -43,3 +43,32 @@ func TestRedirect(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIsIssueRequest(t *testing.T) {
|
||||||
|
wantNum := "https://code.google.com/p/camlistore/issues/detail?id=34"
|
||||||
|
wantList := "https://code.google.com/p/camlistore/issues/list"
|
||||||
|
tests := []struct {
|
||||||
|
urlPath string
|
||||||
|
redirects bool
|
||||||
|
dest string
|
||||||
|
}{
|
||||||
|
{"/issue", true, wantList},
|
||||||
|
{"/issue/", true, wantList},
|
||||||
|
{"/issue/34", true, wantNum},
|
||||||
|
{"/issue34", false, ""},
|
||||||
|
{"/issues", true, wantList},
|
||||||
|
{"/issues/", true, wantList},
|
||||||
|
{"/issues/34", true, wantNum},
|
||||||
|
{"/issues34", false, ""},
|
||||||
|
{"/bugs", true, wantList},
|
||||||
|
{"/bugs/", true, wantList},
|
||||||
|
{"/bugs/34", true, wantNum},
|
||||||
|
{"/bugs34", false, ""},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
dest, ok := issueRedirect(tt.urlPath)
|
||||||
|
if ok != tt.redirects || dest != tt.dest {
|
||||||
|
t.Errorf("issueRedirect(%q) = %q, %v; want %q, %v", tt.urlPath, dest, ok, tt.dest, tt.redirects)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue