all repos — flounder @ 4647b0b9cc545a63314706b0c05ca69e18b94aa4

A small site builder for the Gemini protocol

webdav.go (view raw)

 1package main
 2
 3import (
 4	"fmt"
 5	"golang.org/x/net/webdav"
 6	"net/http"
 7)
 8
 9func webdavHandler(w http.ResponseWriter, r *http.Request) {
10	// get user
11	if r.Header.Get("Authorization") == "" {
12		w.Header().Set("WWW-Authenticate", "Basic realm=\"wevdav\"")
13		http.Error(w, "Authentication Error", http.StatusUnauthorized)
14		return
15	}
16	user, pass, ok := r.BasicAuth()
17	if ok && (checkAuth(user, pass) == nil) {
18		webdavHandler := webdav.Handler{
19			FileSystem: webdav.Dir(getUserDirectory(user)),
20			Prefix:     "/webdav/",
21			LockSystem: webdav.NewMemLS(),
22			Logger: func(r *http.Request, e error) {
23				fmt.Println(e)
24			},
25		}
26		webdavHandler.ServeHTTP(w, r)
27	} else {
28		http.Error(w, "Authentication Error", http.StatusUnauthorized)
29	}
30}