fork golang.org/x/net/webdav for customization
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user