mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
Pass request context to backend interface
This aligns the caldav interface with the carddav one (see #53).
This commit is contained in:
parent
106d4e1c88
commit
52215c1690
@ -1,6 +1,7 @@
|
|||||||
package caldav
|
package caldav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -14,10 +15,10 @@ import (
|
|||||||
|
|
||||||
// Backend is a CalDAV server backend.
|
// Backend is a CalDAV server backend.
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
Calendar() (*Calendar, error)
|
Calendar(ctx context.Context) (*Calendar, error)
|
||||||
GetCalendarObject(path string, req *CalendarCompRequest) (*CalendarObject, error)
|
GetCalendarObject(ctx context.Context, path string, req *CalendarCompRequest) (*CalendarObject, error)
|
||||||
ListCalendarObjects(req *CalendarCompRequest) ([]CalendarObject, error)
|
ListCalendarObjects(ctx context.Context, req *CalendarCompRequest) ([]CalendarObject, error)
|
||||||
QueryCalendarObjects(query *CalendarQuery) ([]CalendarObject, error)
|
QueryCalendarObjects(ctx context.Context, query *CalendarQuery) ([]CalendarObject, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler handles CalDAV HTTP requests. It can be used to create a CalDAV
|
// Handler handles CalDAV HTTP requests. It can be used to create a CalDAV
|
||||||
@ -60,7 +61,7 @@ func (h *Handler) handleReport(w http.ResponseWriter, r *http.Request) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if report.Query != nil {
|
if report.Query != nil {
|
||||||
return h.handleQuery(w, report.Query)
|
return h.handleQuery(r, w, report.Query)
|
||||||
} else if report.Multiget != nil {
|
} else if report.Multiget != nil {
|
||||||
return h.handleMultiget(w, report.Multiget)
|
return h.handleMultiget(w, report.Multiget)
|
||||||
}
|
}
|
||||||
@ -100,7 +101,7 @@ func decodeCompFilter(el *compFilter) (*CompFilter, error) {
|
|||||||
return cf, nil
|
return cf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) handleQuery(w http.ResponseWriter, query *calendarQuery) error {
|
func (h *Handler) handleQuery(r *http.Request, w http.ResponseWriter, query *calendarQuery) error {
|
||||||
var q CalendarQuery
|
var q CalendarQuery
|
||||||
// TODO: calendar-data in query.Prop
|
// TODO: calendar-data in query.Prop
|
||||||
cf, err := decodeCompFilter(&query.Filter.CompFilter)
|
cf, err := decodeCompFilter(&query.Filter.CompFilter)
|
||||||
@ -109,7 +110,7 @@ func (h *Handler) handleQuery(w http.ResponseWriter, query *calendarQuery) error
|
|||||||
}
|
}
|
||||||
q.CompFilter = *cf
|
q.CompFilter = *cf
|
||||||
|
|
||||||
cos, err := h.Backend.QueryCalendarObjects(&q)
|
cos, err := h.Backend.QueryCalendarObjects(r.Context(), &q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -150,7 +151,7 @@ func (b *backend) Options(r *http.Request) (caps []string, allow []string, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dataReq CalendarCompRequest
|
var dataReq CalendarCompRequest
|
||||||
_, err = b.Backend.GetCalendarObject(r.URL.Path, &dataReq)
|
_, err = b.Backend.GetCalendarObject(r.Context(), r.URL.Path, &dataReq)
|
||||||
if httpErr, ok := err.(*internal.HTTPError); ok && httpErr.Code == http.StatusNotFound {
|
if httpErr, ok := err.(*internal.HTTPError); ok && httpErr.Code == http.StatusNotFound {
|
||||||
return caps, []string{http.MethodOptions, http.MethodPut}, nil
|
return caps, []string{http.MethodOptions, http.MethodPut}, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@ -174,7 +175,7 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error {
|
|||||||
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
|
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
|
||||||
var resps []internal.Response
|
var resps []internal.Response
|
||||||
if r.URL.Path == "/" {
|
if r.URL.Path == "/" {
|
||||||
cal, err := b.Backend.Calendar()
|
cal, err := b.Backend.Calendar(r.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user