simple webdav server
This commit is contained in:
30
cmd/noah-server/noah-server.go
Normal file
30
cmd/noah-server/noah-server.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"golang.org/x/net/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()
|
||||
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
|
||||
}
|
||||
fs.ServeHTTP(w, r)
|
||||
})
|
||||
fmt.Println("wait requests")
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
Reference in New Issue
Block a user