more updates and renaming

This commit is contained in:
Henrique Dias committed 2017-06-19 17:10:03 +01:00
1 parent 1c703e0364
commit 8c19482190
24 files changed
+4823 -4729

No files matched your search

+20 -4
View File
@@ -10,8 +10,6 @@ import (
fm "github.com/hacdias/filemanager"
"github.com/hacdias/filemanager/assets"
"github.com/hacdias/filemanager/page"
"github.com/hacdias/filemanager/utils"
"github.com/hacdias/filemanager/wrapper"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
@@ -74,7 +72,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *fm.Config) (int, error
r.Method = "PROPFIND"
if r.Method == "HEAD" {
w = wrapper.NewResponseWriterNoBody(w)
w = NewResponseWriterNoBody(w)
}
}
case "PROPPATCH", "MOVE", "PATCH", "PUT", "DELETE":
@@ -133,7 +131,7 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *fm.Config) (int, error
if r.Method == http.MethodGet {
// Gets the information of the directory/file
fi, err = fm.GetInfo(r.URL, c, user)
code = utils.ErrorToHTTPCode(err, false)
code = errorToHTTPCode(err, false)
if err != nil {
if r.Method == http.MethodGet {
return page.PrintErrorHTML(w, code, err)
@@ -171,3 +169,21 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *fm.Config) (int, error
return http.StatusNotImplemented, nil
}
// errorToHTTPCode converts errors to HTTP Status Code.
func errorToHTTPCode(err error, gone bool) int {
switch {
case os.IsPermission(err):
return http.StatusForbidden
case os.IsNotExist(err):
if !gone {
return http.StatusNotFound
}
return http.StatusGone
case os.IsExist(err):
return http.StatusGone
default:
return http.StatusInternalServerError
}
}