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
ee0ebc986c
commit
49902f9059
7 changed files with 1419 additions and 9 deletions
37
examples/webdav/main.go
Normal file
37
examples/webdav/main.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/infinite-iroha/touka"
|
||||
"github.com/infinite-iroha/touka/webdav"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := touka.Default()
|
||||
|
||||
// Create a directory for the OS file system.
|
||||
if err := os.MkdirAll("public", 0755); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Create a new WebDAV handler with the OS file system.
|
||||
fs, err := webdav.NewOSFS("public")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
handler := webdav.NewHandler("/webdav", fs, webdav.NewMemLock(), log.New(os.Stdout, "", 0))
|
||||
|
||||
// Mount the WebDAV handler on the "/webdav/" route.
|
||||
webdavMethods := []string{
|
||||
"OPTIONS", "GET", "HEAD", "DELETE", "PUT", "MKCOL", "COPY", "MOVE", "PROPFIND", "PROPPATCH", "LOCK", "UNLOCK",
|
||||
}
|
||||
r.HandleFunc(webdavMethods, "/webdav/*path", handler.ServeTouka)
|
||||
|
||||
log.Println("Touka WebDAV Server starting on :8080...")
|
||||
if err := r.RunShutdown(":8080", 10*time.Second); err != nil {
|
||||
log.Fatalf("Touka server failed to start: %v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue