yeah
This commit is contained in:
24
main.go
24
main.go
@@ -106,20 +106,25 @@ func main() {
|
||||
principalPath := prefix + fmt.Sprintf("/%s/", user)
|
||||
ctx := context.WithValue(r.Context(), "principal", principalPath)
|
||||
|
||||
// set header for carddav
|
||||
// set header for carddav if user has address books
|
||||
if slices.Contains([]string{
|
||||
"/", prefix + "/",
|
||||
"/.well-known/carddav",
|
||||
prefix + "/.well-known/carddav",
|
||||
principalPath,
|
||||
strings.TrimSuffix(principalPath, "/"),
|
||||
}, r.URL.Path) || strings.Contains(r.URL.Path, "/addressbooks/") {
|
||||
w.Header().Add("DAV", "addressbook")
|
||||
if has, _ := be.HasAddressBooks(ctx); has {
|
||||
w.Header().Add("DAV", "addressbook")
|
||||
}
|
||||
}
|
||||
|
||||
// for caldav discovery
|
||||
// for caldav and carddav discovery
|
||||
if slices.Contains([]string{
|
||||
"/.well-known/caldav",
|
||||
prefix + "/.well-known/caldav",
|
||||
"/.well-known/carddav",
|
||||
prefix + "/.well-known/carddav",
|
||||
}, r.URL.Path) {
|
||||
http.Redirect(w, r, fmt.Sprintf("%s://%s%s", scheme, r.Host, principalPath), http.StatusMovedPermanently)
|
||||
return
|
||||
@@ -142,19 +147,14 @@ func main() {
|
||||
// catch weird requests
|
||||
} else {
|
||||
|
||||
if strings.HasSuffix(r.URL.Path, user+"/") || strings.HasSuffix(r.URL.Path, user) {
|
||||
// For principal path, use merged discovery handler
|
||||
if strings.HasSuffix(r.URL.Path, user+"/") || strings.HasSuffix(r.URL.Path, user) || r.URL.Path == "/" || r.URL.Path == prefix+"/" {
|
||||
// For principal path or root, use merged discovery handler
|
||||
if r.Method == "PROPFIND" {
|
||||
extra.HandleDiscoveryPropfind(r, ctx, caldavHandler, w, be)
|
||||
} else if r.Method == "OPTIONS" {
|
||||
extra.HandleDiscoveryOptions(r, ctx, caldavHandler, w, be)
|
||||
} else {
|
||||
caldavHandler.ServeHTTP(w, r.WithContext(ctx))
|
||||
// Ensure DAV header includes addressbook for OPTIONS
|
||||
if r.Method == "OPTIONS" {
|
||||
dav := w.Header().Get("DAV")
|
||||
if dav != "" && !strings.Contains(dav, "addressbook") {
|
||||
w.Header().Set("DAV", dav+", addressbook")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
|
||||
Reference in New Issue
Block a user