mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
internal: accomodate for trailign slashes in Multistatus.Get
This commit is contained in:
parent
7f285fdf83
commit
0b2d0a706c
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -98,17 +99,19 @@ func NewMultistatus(resps ...Response) *Multistatus {
|
|||||||
return &Multistatus{Responses: resps}
|
return &Multistatus{Responses: resps}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ms *Multistatus) Get(path string) (*Response, error) {
|
func (ms *Multistatus) Get(p string) (*Response, error) {
|
||||||
|
// Clean the path to avoid issues with trailing slashes
|
||||||
|
p = path.Clean(p)
|
||||||
for i := range ms.Responses {
|
for i := range ms.Responses {
|
||||||
resp := &ms.Responses[i]
|
resp := &ms.Responses[i]
|
||||||
for _, h := range resp.Hrefs {
|
for _, h := range resp.Hrefs {
|
||||||
if h.Path == path {
|
if path.Clean(h.Path) == p {
|
||||||
return resp, resp.Status.Err()
|
return resp, resp.Status.Err()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("webdav: missing response for path %q", path)
|
return nil, fmt.Errorf("webdav: missing response for path %q", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc4918#section-14.24
|
// https://tools.ietf.org/html/rfc4918#section-14.24
|
||||||
|
Loading…
Reference in New Issue
Block a user