all repos — flounder @ b9a8645bc1f8102bacd11b8bb1da8c2876511e89

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	for key, element := range r.Header {
17		fmt.Println(key, element)
18	}
19	fmt.Println(r.Body)
20	user, pass, ok := r.BasicAuth()
21	if ok && (checkAuth(user, pass) == nil) {
22		fmt.Println(user, pass)
23		webdavHandler := webdav.Handler{
24			FileSystem: webdav.Dir(getUserDirectory(user)),
25			Prefix:     "/webdav/",
26			LockSystem: webdav.NewMemLS(),
27		}
28		webdavHandler.ServeHTTP(w, r)
29	} else {
30		http.Error(w, "Authentication Error", http.StatusUnauthorized)
31	}
32}