fork golang.org/x/net/webdav for customization

This commit is contained in:
2021-09-20 07:49:04 -04:00
parent be128c9e4e
commit f3b2e54ef1
24 changed files with 15362 additions and 5 deletions

View File

@@ -3,25 +3,25 @@ package main
import (
"fmt"
"net/http"
"golang.org/x/net/webdav"
"noahcloud/webdav"
)
func main() {
fs := &webdav.Handler{
FileSystem: webdav.Dir("."),
LockSystem: webdav.NewMemLS(),
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method, r.URL.Path)
username, password, ok := r.BasicAuth()
fmt.Println(username, password)
if !ok {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
w.WriteHeader(http.StatusUnauthorized)
return
}
if username != "username" || password != "password" {
http.Error(w, "WebDAV: need authorized!", http.StatusUnauthorized)
return
if username != "vscode" || password != "password" {
//http.Error(w, "WebDAV: need authorized!", http.StatusUnauthorized)
//return
}
fs.ServeHTTP(w, r)
})