Finish the Lock and Unlock feature for webdav.

This commit is contained in:
lishuang
2020-05-06 01:10:17 +08:00
parent ed0aa017db
commit 76c763b84d
5 changed files with 200 additions and 31 deletions

View File

@ -414,20 +414,20 @@ func (b *byExpiry) Pop() interface{} {
return n
}
const infiniteTimeout = -1
const InfiniteTimeout = -1
// ParseTimeout parses the Timeout HTTP header, as per section 10.7. If s is
// empty, an infiniteTimeout is returned.
// empty, an InfiniteTimeout is returned.
func ParseTimeout(s string) (time.Duration, error) {
if s == "" {
return infiniteTimeout, nil
return InfiniteTimeout, nil
}
if i := strings.IndexByte(s, ','); i >= 0 {
s = s[:i]
}
s = strings.TrimSpace(s)
if s == "Infinite" {
return infiniteTimeout, nil
return InfiniteTimeout, nil
}
const pre = "Second-"
if !strings.HasPrefix(s, pre) {

View File

@ -61,7 +61,7 @@ func TestWalkToRoot(t *testing.T) {
}
var lockTestDurations = []time.Duration{
infiniteTimeout, // infiniteTimeout means to never expire.
InfiniteTimeout, // InfiniteTimeout means to never expire.
0, // A zero duration means to expire immediately.
100 * time.Hour, // A very large duration will not expire in these tests.
}
@ -102,7 +102,7 @@ func TestMemLSCanCreate(t *testing.T) {
for _, name := range lockTestNames {
_, err := m.Create(now, LockDetails{
Root: name,
Duration: infiniteTimeout,
Duration: InfiniteTimeout,
ZeroDepth: lockTestZeroDepth(name),
})
if err != nil {
@ -165,7 +165,7 @@ func TestMemLSLookup(t *testing.T) {
for _, name := range lockTestNames {
token, err := m.Create(now, LockDetails{
Root: name,
Duration: infiniteTimeout,
Duration: InfiniteTimeout,
ZeroDepth: lockTestZeroDepth(name),
})
if err != nil {
@ -209,7 +209,7 @@ func TestMemLSConfirm(t *testing.T) {
m := NewMemLS().(*MemLS)
alice, err := m.Create(now, LockDetails{
Root: "/alice",
Duration: infiniteTimeout,
Duration: InfiniteTimeout,
ZeroDepth: false,
})
if err != nil {
@ -218,7 +218,7 @@ func TestMemLSConfirm(t *testing.T) {
tweedle, err := m.Create(now, LockDetails{
Root: "/tweedle",
Duration: infiniteTimeout,
Duration: InfiniteTimeout,
ZeroDepth: false,
})
if err != nil {
@ -644,11 +644,11 @@ func TestParseTimeout(t *testing.T) {
wantErr error
}{{
"",
infiniteTimeout,
InfiniteTimeout,
nil,
}, {
"Infinite",
infiniteTimeout,
InfiniteTimeout,
nil,
}, {
"Infinitesimal",
@ -722,7 +722,7 @@ func TestParseTimeout(t *testing.T) {
// The Go WebDAV package always supports infinite length locks,
// and ignores the fallback after the comma.
"Infinite, Second-4100000000",
infiniteTimeout,
InfiniteTimeout,
nil,
}}

View File

@ -84,7 +84,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (h *Handler) lock(now time.Time, root string) (token string, status int, err error) {
token, err = h.LockSystem.Create(now, LockDetails{
Root: root,
Duration: infiniteTimeout,
Duration: InfiniteTimeout,
ZeroDepth: true,
})
if err != nil {

View File

@ -65,6 +65,7 @@ func ReadLockInfo(r io.Reader) (li LockInfo, status int, err error) {
// We only support exclusive (non-shared) write locks. In practice, these are
// the only types of locks that seem to matter.
if li.Exclusive == nil || li.Shared != nil || li.Write == nil {
// we should support Shared lock.
return LockInfo{}, http.StatusNotImplemented, ErrUnsupportedLockInfo
}
return li, 0, nil