mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-02-03 08:51:11 +08:00
feat: add native WebDAV submodule
This commit introduces a new, high-performance, and extensible WebDAV submodule, implemented natively without external dependencies. The submodule includes: - A core WebDAV handler that supports essential methods: PROPFIND, MKCOL, GET, PUT, DELETE, COPY, MOVE, LOCK, and UNLOCK. - An extensible design using a `FileSystem` interface to decouple the protocol logic from the storage backend. - Two `FileSystem` implementations: - `MemFS`: An in-memory, tree-based filesystem for testing and ephemeral storage. - `OSFS`: A secure, OS-based filesystem that interacts with the local disk and includes path traversal protection. - A `LockSystem` interface with an in-memory implementation (`MemLock`) to support resource locking (DAV Class 2). - Comprehensive unit tests covering all major functionalities. - A working example application demonstrating how to mount and use the submodule with a local directory. The Touka framework's core has been updated to recognize WebDAV-specific HTTP methods.
This commit is contained in:
parent
8e10d51d6d
commit
33e5d5474d
4 changed files with 68 additions and 17 deletions
|
|
@ -585,11 +585,11 @@ func (h *Handler) handleProppatch(c *touka.Context) {
|
|||
c.Status(http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
func (h *Handler) stripPrefix(path string) string {
|
||||
func (h *Handler) stripPrefix(p string) string {
|
||||
if h.Prefix == "/" {
|
||||
return path
|
||||
return p
|
||||
}
|
||||
return "/" + strings.TrimPrefix(path, h.Prefix)
|
||||
return strings.TrimPrefix(p, h.Prefix)
|
||||
}
|
||||
|
||||
func (h *Handler) handleLock(c *touka.Context) {
|
||||
|
|
@ -599,7 +599,15 @@ func (h *Handler) handleLock(c *touka.Context) {
|
|||
}
|
||||
|
||||
path, _ := c.Get("webdav_path")
|
||||
token := c.GetReqHeader("If")
|
||||
tokenHeader := c.GetReqHeader("If")
|
||||
var token string
|
||||
if tokenHeader != "" {
|
||||
// Basic parsing for <opaquelocktoken:c2134f...>
|
||||
if strings.HasPrefix(tokenHeader, "(<") && strings.HasSuffix(tokenHeader, ">)") {
|
||||
token = strings.TrimPrefix(tokenHeader, "(<")
|
||||
token = strings.TrimSuffix(token, ">)")
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh lock
|
||||
if token != "" {
|
||||
|
|
@ -666,7 +674,7 @@ func parseTimeout(timeoutStr string) (time.Duration, error) {
|
|||
return seconds, nil
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
return 0, os.ErrInvalid
|
||||
}
|
||||
|
||||
func (h *Handler) handleUnlock(c *touka.Context) {
|
||||
|
|
@ -675,12 +683,16 @@ func (h *Handler) handleUnlock(c *touka.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
token := c.GetReqHeader("Lock-Token")
|
||||
if token == "" {
|
||||
tokenHeader := c.GetReqHeader("Lock-Token")
|
||||
if tokenHeader == "" {
|
||||
c.Status(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Basic parsing for <urn:uuid:f81d4fae...>
|
||||
token := strings.TrimPrefix(tokenHeader, "<")
|
||||
token = strings.TrimSuffix(token, ">")
|
||||
|
||||
if err := h.LockSystem.Unlock(c.Context(), token); err != nil {
|
||||
c.Status(http.StatusConflict)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue