summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-03-03 14:47:04 +0100
committerache <ache@ache.one>2019-03-03 14:47:04 +0100
commitc0d86f3faa6a484928602434b8df8a1c580956e5 (patch)
treed40239456f60838571b84d7aec5d5aca9aa1ba71
parentKawaii power (diff)
OPTIONS Methode
-rw-r--r--server.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/server.go b/server.go
index dcae977..7ef143b 100644
--- a/server.go
+++ b/server.go
@@ -22,10 +22,9 @@ func verifyEmptyBody( w http.ResponseWriter, r *http.Request) error {
if r.Body != nil {
p := make([]byte, 1)
_,er := r.Body.Read(p)
-
if er == nil {
+ r.Body.Close()
w.WriteHeader(http.StatusUnsupportedMediaType)
- fmt.Println("The body of the request isn't empty. It should be.")
return errors.New("Body not empty")
}
}
@@ -238,7 +237,7 @@ func handleMkcol( w http.ResponseWriter, r *http.Request) {
fmt.Printf("Trying to Mkcol [%s]\n", filename)
// 8.4 RFC4918 - Must return 415 (Unsupported Media Type) if body and should not.
- verifyEmptyBody(w, r)
+ if verifyEmptyBody(w, r) != nil { return }
fmt.Printf(" Base [%s]\n", path.Base(filename))
fmt.Printf(" Dir [%s]\n", path.Dir(filename))
@@ -253,17 +252,18 @@ func handleMkcol( w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Collection created")
}
func handleOptions( w http.ResponseWriter, r *http.Request) {
-
- // 8.4 RFC4918 - Must return 415 (Unsupported Media Type) if body and should not.
- if r.Body != nil {
- w.WriteHeader(http.StatusUnsupportedMediaType)
+ if verifyEmptyBody(w, r) != nil {
fmt.Println("The body of the request isn't empty. It should be.")
- return
+ return;
}
+ w.Header().Add("Allow", "GET,OPTIONS,HEAD,MKCOL,PUT,PROPFIND,PROPPATCH,DELETE,MOVE,COPY");
+ w.Header().Add("Server","Davy/1.0 Fun server");
+ w.Header().Add("DAV","1");
+ w.WriteHeader(http.StatusOK);
}
func handleCopy( w http.ResponseWriter, r *http.Request) {
- verifyEmptyBody(w, r)
+ fmt.Println("The body of the request isn't empty. It should be.")
}
func handleMove( w http.ResponseWriter, r *http.Request) {
filename := r.URL.Path[1:]
@@ -273,7 +273,7 @@ func handleMove( w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Overwrite") != "" {
overwrite = r.Header.Get("Overwrite")
}
- verifyEmptyBody(w, r)
+ if verifyEmptyBody(w, r) != nil { return }
fmt.Println(dest)
@@ -350,6 +350,7 @@ func handleMethod( w http.ResponseWriter, r *http.Request) {
case http.MethodDelete:
handleDelete(w, r)
case http.MethodOptions:
+ fmt.Println("🦊");
handleOptions(w, r)
case "MOVE":
handleDelete(w, r)
@@ -416,13 +417,13 @@ func main() {
}
tmpl = template.Must(template.New("dir.html").Funcs(fmap).ParseFiles("dir.html"))
- base_wd,_ := os.Getwd();
+ baseWd,_ := os.Getwd();
http.HandleFunc("/pink.svg", func(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, base_wd + "/pink.svg")
+ http.ServeFile(w, r, baseWd + "/pink.svg")
});
http.HandleFunc("/test.svg", func(w http.ResponseWriter, r *http.Request) {
- http.ServeFile(w, r, base_wd + "/test.svg")
+ http.ServeFile(w, r, baseWd + "/test.svg")
})
if err := os.Chdir(dir) ; err != nil {