mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-02-03 08:51:11 +08:00
This commit introduces a new, high-performance, and extensible WebDAV submodule, implemented natively without external dependencies. It also adds a high-level API to simplify common use cases. 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, including robust path traversal and symlink protection. - A `LockSystem` interface with an in-memory implementation (`MemLock`) that supports resource locking and includes a graceful shutdown mechanism. - A high-level API in `webdav/easy.go` (`Serve`, `Register`) to simplify serving local directories. - RFC 4918 compliance for core operations. - Performance optimizations, including `sync.Pool` for object reuse and `sync/atomic` for lock-free field access. - Comprehensive unit tests and a working example application. The Touka framework's core has been updated to recognize all WebDAV-specific HTTP methods. This implementation addresses numerous points from detailed code reviews, including security vulnerabilities, memory leaks, RFC compliance issues, and path handling bugs.
29 lines
604 B
Go
29 lines
604 B
Go
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)
|
|
}
|
|
|
|
// Serve the "public" directory on the "/webdav/" route.
|
|
if err := webdav.Serve(r, "/webdav", "public"); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|