Optimize webdav

This commit is contained in:
Ben Sarmiento
2023-11-21 10:32:14 +01:00
parent 10980f4f3e
commit cbf14e953f
3 changed files with 54 additions and 53 deletions

View File

@@ -1,27 +1,39 @@
package dav
func Directory(path string) Response {
import "fmt"
func DavDirectory(path, added string) Response {
return Response{
Href: "/" + customPathEscape(path),
Propstat: PropStat{
Prop: Prop{
ResourceType: ResourceType{Value: "<d:collection/>"},
LastModified: added,
},
Status: "HTTP/1.1 200 OK",
},
}
}
func File(path string, fileSize int64, added string, link string) Response {
func DavFile(path string, fileSize int64, added string, link string) Response {
return Response{
Href: "/" + customPathEscape(path),
Propstat: PropStat{
Prop: Prop{
ContentLength: fileSize,
CreationDate: added,
LastModified: added,
},
Status: "HTTP/1.1 200 OK",
},
}
}
// optimized versions, no more marshalling
func Directory(path, added string) string {
return fmt.Sprintf("<d:response><d:href>/%s</d:href><d:propstat><d:prop><d:resourcetype><d:collection/></d:resourcetype></d:prop><d:prop><d:getlastmodified>%s</d:getlastmodified></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>", customPathEscape(path), added)
}
func File(path string, fileSize int64, added string) string {
return fmt.Sprintf("<d:response><d:href>/%s</d:href><d:propstat><d:prop><d:resourcetype></d:resourcetype><d:getcontentlength>%d</d:getcontentlength><d:getlastmodified>%s</d:getlastmodified></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>", customPathEscape(path), fileSize, added)
}

View File

@@ -23,7 +23,6 @@ type PropStat struct {
type Prop struct {
ResourceType ResourceType `xml:"d:resourcetype"`
ContentLength int64 `xml:"d:getcontentlength,omitempty"`
CreationDate string `xml:"d:creationdate,omitempty"`
LastModified string `xml:"d:getlastmodified,omitempty"`
}