summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-12 21:52:32 +0100
committerache <ache@ache.one>2019-02-12 21:52:32 +0100
commit28fb840e87cdfb5fd2c319903ea9b2239335ebf1 (patch)
treea19f0ea954a72c6cdd4959c5fe52ed1eb9532f7d /server.go
parentInit dir args option (diff)
Support HEAD
Diffstat (limited to 'server.go')
-rw-r--r--server.go53
1 files changed, 36 insertions, 17 deletions
diff --git a/server.go b/server.go
index c38d216..99b5d29 100644
--- a/server.go
+++ b/server.go
@@ -11,7 +11,7 @@ import (
var tmpl *template.Template
-func handleGet( w http.ResponseWriter, r *http.Request) {
+func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
path := r.URL.Path[1:]
if path == "" {
@@ -25,9 +25,11 @@ func handleGet( w http.ResponseWriter, r *http.Request) {
case err != nil || stat == nil :
if os.IsNotExist(err) {
w.WriteHeader(http.StatusNotFound)
- fmt.Fprintln(w, "File not found")
- fmt.Fprintln(w, "")
- fmt.Fprintln(w, "Sry bro")
+ if ! headOnly {
+ fmt.Fprintln(w, "File not found")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "Sry bro")
+ }
return
}
case stat.IsDir() :
@@ -43,9 +45,11 @@ func handleGet( w http.ResponseWriter, r *http.Request) {
if err != nil {
w.WriteHeader(http.StatusNotFound)
- fmt.Fprintln(w, "File not found")
- fmt.Fprintln(w, "")
- fmt.Fprintln(w, "Sry bro")
+ if !headOnly {
+ fmt.Fprintln(w, "File not found")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "Sry bro")
+ }
return
}
@@ -54,9 +58,11 @@ func handleGet( w http.ResponseWriter, r *http.Request) {
if err != nil {
w.WriteHeader(http.StatusNotFound)
- fmt.Fprintln(w, "File not found")
- fmt.Fprintln(w, "")
- fmt.Fprintln(w, "Sry bro")
+ if !headOnly {
+ fmt.Fprintln(w, "File not found")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, "Sry bro")
+ }
}
for _, file := range fileInfo {
@@ -71,28 +77,41 @@ func handleGet( w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w, Collection{ "Title" , files})
case stat.Mode().IsRegular():
- http.ServeFile(w, r, r.URL.Path[1:])
+ if !headOnly {
+ http.ServeFile(w, r, r.URL.Path[1:])
+ }
default:
}
}
-func handlePost( w http.ResponseWriter, r *http.Request) {
-}
func handleDelete( w http.ResponseWriter, r *http.Request) {
}
func handlePut( w http.ResponseWriter, r *http.Request) {
}
+func handleMkcol( w http.ResponseWriter, r *http.Request) {
+}
+func handleOptions( w http.ResponseWriter, r *http.Request) {
+}
+func handleCopy( w http.ResponseWriter, r *http.Request) {
+}
func handleMethod( w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
- handleGet(w, r)
- case http.MethodPost:
- handlePost(w, r)
+ handleGet(w, r, false)
+ case http.MethodHead:
+ handleGet(w, r, true)
case http.MethodPut:
handlePut(w, r)
case http.MethodDelete:
- // Remove the record.
handleDelete(w, r)
+ case "MKCOL":
+ handleMkcol(w, r)
+ case "LOCK":
+ fallthrough
+ case "UNLOCK":
+ fallthrough
+ case http.MethodPost:
+ fallthrough
default:
w.WriteHeader(http.StatusTeapot)
fmt.Fprintln(w, "Sry, i'm a teapot >///<")