mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
caldav: only call CurrentUserPrincipal when necessary
This commit is contained in:
parent
e971269ffb
commit
a346d42f42
@ -51,17 +51,18 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
principalPath, err := h.Backend.CurrentUserPrincipal(r.Context())
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "caldav: failed to determine current user principal", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.URL.Path == "/.well-known/caldav" {
|
if r.URL.Path == "/.well-known/caldav" {
|
||||||
|
principalPath, err := h.Backend.CurrentUserPrincipal(r.Context())
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "caldav: failed to determine current user principal", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
http.Redirect(w, r, principalPath, http.StatusMovedPermanently)
|
http.Redirect(w, r, principalPath, http.StatusMovedPermanently)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "REPORT":
|
case "REPORT":
|
||||||
err = h.handleReport(w, r)
|
err = h.handleReport(w, r)
|
||||||
@ -378,6 +379,7 @@ func (b *backend) propfindUserPrincipal(ctx context.Context, propfind *internal.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
props := map[xml.Name]internal.PropfindFunc{
|
props := map[xml.Name]internal.PropfindFunc{
|
||||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
|
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
|
||||||
@ -390,13 +392,13 @@ func (b *backend) propfindUserPrincipal(ctx context.Context, propfind *internal.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) propfindCalendar(ctx context.Context, propfind *internal.Propfind, cal *Calendar) (*internal.Response, error) {
|
func (b *backend) propfindCalendar(ctx context.Context, propfind *internal.Propfind, cal *Calendar) (*internal.Response, error) {
|
||||||
principalPath, err := b.Backend.CurrentUserPrincipal(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
props := map[xml.Name]internal.PropfindFunc{
|
props := map[xml.Name]internal.PropfindFunc{
|
||||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
|
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: path}}, nil
|
||||||
},
|
},
|
||||||
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return internal.NewResourceType(internal.CollectionName, calendarName), nil
|
return internal.NewResourceType(internal.CollectionName, calendarName), nil
|
||||||
@ -441,13 +443,13 @@ func (b *backend) propfindCalendar(ctx context.Context, propfind *internal.Propf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) propfindCalendarObject(ctx context.Context, propfind *internal.Propfind, co *CalendarObject) (*internal.Response, error) {
|
func (b *backend) propfindCalendarObject(ctx context.Context, propfind *internal.Propfind, co *CalendarObject) (*internal.Response, error) {
|
||||||
principalPath, err := b.Backend.CurrentUserPrincipal(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
props := map[xml.Name]internal.PropfindFunc{
|
props := map[xml.Name]internal.PropfindFunc{
|
||||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
|
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: path}}, nil
|
||||||
},
|
},
|
||||||
internal.GetContentTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.GetContentTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.GetContentType{Type: ical.MIMEType}, nil
|
return &internal.GetContentType{Type: ical.MIMEType}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user