Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 20:29:11 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-02-11 20:29:11 +0300
commit920b15f69cd7749ab5f45b121132e92de2ef6e15 (patch)
tree1b7fed68042a8a537fe1c8e8a59a3cbdc9176ee6 /domain.go
parentf97ebb63782cb6ac681268651a2234e942b7e90a (diff)
Reduce code complexity
Diffstat (limited to 'domain.go')
-rw-r--r--domain.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/domain.go b/domain.go
index 87e8a4c3..f9ddc7c1 100644
--- a/domain.go
+++ b/domain.go
@@ -40,7 +40,7 @@ func (d *domain) serveFile(w http.ResponseWriter, r *http.Request, fullPath stri
return true
}
-func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) {
+func (d *domain) resolvePath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) {
publicPath := filepath.Join(*pagesRoot, d.Group, projectName, "public")
fullPath = filepath.Join(publicPath, subPath)
@@ -53,7 +53,11 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s
err = fmt.Errorf("%q should be in %q", fullPath, publicPath)
return
}
+ return
+}
+func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string) (fullPath string, err error) {
+ fullPath = path
fi, err := os.Lstat(fullPath)
if err != nil {
return
@@ -77,11 +81,15 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s
}
func (d *domain) tryFile(w http.ResponseWriter, r *http.Request, projectName, subPath string) bool {
- fullPath, err := d.fullPath(w, r, projectName, subPath)
+ path, err := d.resolvePath(w, r, projectName, subPath)
+ if err != nil {
+ return false
+ }
+ path, err = d.checkPath(w, r, path)
if err != nil {
return false
}
- return d.serveFile(w, r, fullPath)
+ return d.serveFile(w, r, path)
}
func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) {