diff options
-rw-r--r-- | domain.go | 8 | ||||
-rw-r--r-- | domain_test.go | 14 | ||||
-rw-r--r-- | main.go | 7 |
3 files changed, 19 insertions, 10 deletions
@@ -65,6 +65,14 @@ func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string) // If this file is directory, open the index.html if fi.IsDir() { + // If the URL doesn't end with /, send location to client + if !strings.HasSuffix(r.URL.Path, "/") { + newURL := *r.URL + newURL.Path += "/" + http.Redirect(w, r, newURL.String(), 302) + return + } + fullPath = filepath.Join(fullPath, "index.html") fi, err = os.Lstat(fullPath) if err != nil { diff --git a/domain_test.go b/domain_test.go index 582779ea..4af2feb5 100644 --- a/domain_test.go +++ b/domain_test.go @@ -15,18 +15,18 @@ func TestGroupServeHTTP(t *testing.T) { assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/", nil, "main-dir") assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/index.html", nil, "main-dir") - assert.HTTPRedirect(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project", nil) + assert.True(t, assert.HTTPRedirect(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project", nil)) assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/", nil, "project-subdir") assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/index.html", nil, "project-subdir") - assert.HTTPRedirect(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/subdir", nil) + assert.True(t, assert.HTTPRedirect(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/subdir", nil)) assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/subdir/", nil, "project-subsubdir") assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project2/", nil, "project2-main") assert.HTTPBodyContains(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project2/index.html", nil, "project2-main") - assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink", nil) - assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink/index.html", nil) - assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink/subdir/", nil) - assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/fifo", nil) - assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/not-existing-file", nil) + assert.True(t, assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink", nil)) + assert.True(t, assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink/index.html", nil)) + assert.True(t, assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/symlink/subdir/", nil)) + assert.True(t, assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/project/fifo", nil)) + assert.True(t, assert.HTTPError(t, testGroup.ServeHTTP, "GET", "http://group.test.io/not-existing-file", nil)) } func TestDomainServeHTTP(t *testing.T) { @@ -59,8 +59,8 @@ func main() { var pagesRoot = flag.String("pages-root", "shared/pages", "The directory where pages are stored") var pagesDomain = flag.String("pages-domain", "gitlab-example.com", "The domain to serve static pages") - fmt.Printf("GitLab Pages Daemon %s (%s)", VERSION, REVISION) - fmt.Printf("URL: https://gitlab.com/gitlab-org/gitlab-pages") + fmt.Printf("GitLab Pages Daemon %s (%s)\n", VERSION, REVISION) + fmt.Printf("URL: https://gitlab.com/gitlab-org/gitlab-pages\n") flag.Parse() err := os.Chdir(*pagesRoot) @@ -69,7 +69,6 @@ func main() { } var app theApp - app.Domain = strings.ToLower(*pagesDomain) app.RedirectHTTP = *redirectHTTP app.HTTP2 = *useHTTP2 @@ -99,4 +98,6 @@ func main() { l, app.ListenHTTPS = createSocket(*listenProxy) defer l.Close() } + + app.Run() } |