all repos — flounder @ 0c334fb679f6a4418ac74503b30014d660770349

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		fmt.Println(user, pass)
19		webdavHandler := webdav.Handler{
20			FileSystem: webdav.Dir(getUserDirectory(user)),
21			Prefix:     "/webdav/",
22			LockSystem: nil, //webdav.NewMemLS(),
23		}
24		webdavHandler.ServeHTTP(w, r)
25	} else {
26		http.Error(w, "Authentication Error", http.StatusUnauthorized)
27	}
28}