summaryrefslogtreecommitdiff
path: root/src/edit/dir.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/edit/dir.go')
-rw-r--r--src/edit/dir.go42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/edit/dir.go b/src/edit/dir.go
index d07eb78..8315dc0 100644
--- a/src/edit/dir.go
+++ b/src/edit/dir.go
@@ -22,20 +22,14 @@ func ServeGit(out http.ResponseWriter, in *http.Request) {
tree, err := GitLsTree()
errcheck(err)
file, fileExists := tree[upath]
- if in.Method != http.MethodPut {
- if !fileExists {
- http.NotFound(out, in)
+ if file.Type == "tree" && in.Method != http.MethodPut {
+ if !strings.HasSuffix(in.URL.Path, "/") {
+ out.Header().Set("Location", path.Base(upath)+"/")
+ out.WriteHeader(http.StatusMovedPermanently)
return
}
- if file.Type == "tree" {
- if !strings.HasSuffix(in.URL.Path, "/") {
- out.Header().Set("Location", path.Base(upath)+"/")
- out.WriteHeader(http.StatusMovedPermanently)
- return
- }
- if !strings.HasSuffix(upath, "/") {
- upath = upath + "/"
- }
+ if !strings.HasSuffix(upath, "/") {
+ upath = upath + "/"
}
}
@@ -45,9 +39,17 @@ func ServeGit(out http.ResponseWriter, in *http.Request) {
if file.Type == "tree" {
errcheck(renderViewTree(out, upath, tree))
} else {
- errcheck(renderViewBlob(out, upath, file))
+ if fileExists {
+ errcheck(renderViewBlob(out, upath, &file))
+ } else {
+ errcheck(renderViewBlob(out, upath, nil))
+ }
+ }
+ if fileExists {
+ out.WriteHeader(http.StatusOK)
+ } else {
+ out.WriteHeader(http.StatusNotFound)
}
- out.WriteHeader(http.StatusOK)
case http.MethodPut:
username := in.Header.Get("X-Nginx-User")
userinfo, err := user.Lookup(username)
@@ -76,6 +78,10 @@ func ServeGit(out http.ResponseWriter, in *http.Request) {
out.WriteHeader(http.StatusCreated)
}
case http.MethodDelete:
+ if !fileExists {
+ http.NotFound(out, in)
+ return
+ }
username := in.Header.Get("X-Nginx-User")
userinfo, err := user.Lookup(username)
errcheck(err)
@@ -97,10 +103,18 @@ func ServeGit(out http.ResponseWriter, in *http.Request) {
errcheck(renderDeleted(out, upath))
out.WriteHeader(http.StatusOK)
case http.MethodOptions:
+ if !fileExists {
+ http.NotFound(out, in)
+ return
+ }
// POST because PostHack
out.Header().Set("Allow", "GET, HEAD, PUT, POST, DELETE, OPTIONS")
out.WriteHeader(http.StatusOK)
default:
+ if !fileExists {
+ http.NotFound(out, in)
+ return
+ }
out.Header().Set("Allow", "GET, HEAD, PUT, POST, DELETE, OPTIONS")
out.WriteHeader(http.StatusMethodNotAllowed)
}