mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-02-03 00:41:10 +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 and incorporates numerous fixes based on detailed code reviews. Features: - A core WebDAV handler supporting `PROPFIND`, `MKCOL`, `GET`, `PUT`, `DELETE`, `COPY`, `MOVE`, `LOCK`, `UNLOCK`. - An extensible design with `FileSystem` and `LockSystem` interfaces. - `MemFS`: A robust, tree-based in-memory filesystem for testing. - `OSFS`: A secure OS-based filesystem with protection against path traversal and symlink attacks. - `MemLock`: An in-memory locking system with graceful shutdown to prevent resource leaks. - A high-level API (`webdav.Serve`, `webdav.Register`) for ease of use. Fixes & Improvements: - Security: Patched directory traversal and symlink vulnerabilities. Ensured secure lock token generation. - RFC Compliance: Corrected status codes for `COPY`/`MOVE` (201 vs 204), `DELETE` on non-empty collections (409), and `Timeout` header parsing. - Performance: Implemented `sync.Pool` for object reuse and `sync/atomic` for file size management to reduce GC pressure. - Robustness: Fixed numerous bugs related to path handling, resource cleanup (goroutine leaks), and header parsing. Integration: - The Touka framework's core has been updated to recognize all necessary WebDAV methods. - Includes comprehensive unit tests and a working example.
31 lines
634 B
Go
31 lines
634 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.
|
|
closer, err := webdav.Serve(r, "/webdav", "public")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer closer.Close()
|
|
|
|
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)
|
|
}
|
|
}
|