or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bpf.mdcontext-ctxhttp.mdcontext.mddict.mddns-dnsmessage.mdhtml-atom.mdhtml-charset.mdhtml.mdhttp-httpguts.mdhttp-httpproxy.mdhttp2-h2c.mdhttp2-hpack.mdhttp2.mdicmp.mdidna.mdindex.mdipv4.mdipv6.mdnettest.mdnetutil.mdproxy.mdpublicsuffix.mdquic-qlog.mdquic.mdtrace.mdwebdav.mdwebsocket.mdxsrftoken.md
tile.json

webdav.mddocs/

WebDAV Server and Client

Package webdav provides a WebDAV server implementation.

Import

import "golang.org/x/net/webdav"

Constants

const (
    StatusMulti               = 207
    StatusUnprocessableEntity = 422
    StatusLocked              = 423
    StatusFailedDependency    = 424
    StatusInsufficientStorage = 507
)

Variables

var (
    ErrConfirmationFailed = errors.New("webdav: confirmation failed")
    ErrForbidden          = errors.New("webdav: forbidden")
    ErrLocked             = errors.New("webdav: locked")
    ErrNoSuchLock         = errors.New("webdav: no such lock")
)

var ErrNotImplemented = errors.New("not implemented")

Functions

func StatusText(code int) string

Types

Handler

// Handler is a WebDAV HTTP handler
type Handler struct {
    FileSystem  FileSystem  // Required: backing store for the collection
    LockSystem  LockSystem  // Optional: manages locks
    Logger      func(*http.Request, error)
}

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

FileSystem

// FileSystem is a file system tree for WebDAV operations
type FileSystem interface {
    Mkdir(ctx context.Context, name string, perm os.FileMode) error
    OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error)
    RemoveAll(ctx context.Context, name string) error
    Rename(ctx context.Context, oldName, newName string) error
    Stat(ctx context.Context, name string) (os.FileInfo, error)
}

// NewMemFS returns a new in-memory FileSystem implementation
func NewMemFS() FileSystem

// Dir returns a FileSystem for the tree of files rooted at directory dir
func Dir(dir string) FileSystem

File

// File represents an open file
type File interface {
    io.Closer
    io.Reader
    io.Writer
    io.Seeker
    Readdir(count int) ([]os.FileInfo, error)
    Stat() (os.FileInfo, error)
}

LockSystem

// LockSystem manages access to a collection of named resources
type LockSystem interface {
    Confirm(now time.Time, name0, name1 string, conditions ...Condition) (release func(), err error)
    Create(now time.Time, details LockDetails) (token string, err error)
    Refresh(now time.Time, token string, duration time.Duration) (LockDetails, error)
    Unlock(now time.Time, token string) error
}

// NewMemLS returns a new in-memory LockSystem
func NewMemLS() LockSystem

LockDetails

// LockDetails represents lock metadata
type LockDetails struct {
    Root      string
    Duration  time.Duration
    OwnerXML  string
    ZeroDepth bool
}

Condition

// Condition can match a WebDAV resource based on token or ETag
type Condition struct {
    Not   bool
    Token string
    ETag  string
}

Property

// Property represents a single DAV resource property
type Property struct {
    XMLName  xml.Name
    Lang     string `xml:"xml:lang,attr,omitempty"`
    InnerXML []byte `xml:",innerxml"`
}

Propstat

// Propstat represents the result of setting or removing a property
type Propstat struct {
    Props               []Property
    Status              int
    Error               *xmlError
    ResponseDescription string
}

DeadPropsHolder

// DeadPropsHolder manages dead properties for a resource
type DeadPropsHolder interface {
    DeadProps() (map[xml.Name]Property, error)
    Patch([]Proppatch) ([]Propstat, error)
}

ContentTyper

// ContentTyper is an optional interface for FileInfo objects
type ContentTyper interface {
    ContentType(ctx context.Context) (string, error)
}

ETager

// ETager is an optional interface for os.FileInfo objects returned by the FileSystem
type ETager interface {
    // ETag returns an ETag for the file. This should be of the form "value" or W/"value"
    // If this returns error ErrNotImplemented then the error will be ignored
    // and the base implementation will be used instead.
    ETag(ctx context.Context) (string, error)
}

Usage Examples

Basic WebDAV Server

import (
    "golang.org/x/net/webdav"
    "net/http"
)

func startWebDAVServer() error {
    handler := &webdav.Handler{
        FileSystem: webdav.Dir("/tmp/webdav"),
        LockSystem: webdav.NewMemLS(),
        Logger: func(r *http.Request, err error) {
            if err != nil {
                log.Printf("WebDAV error: %v", err)
            }
        },
    }

    return http.ListenAndServe(":8080", handler)
}

In-Memory WebDAV Server

func startMemoryWebDAV() error {
    handler := &webdav.Handler{
        FileSystem: webdav.NewMemFS(),
        LockSystem: webdav.NewMemLS(),
    }

    return http.ListenAndServe(":8080", handler)
}

Custom File System

type customFS struct {
    // Custom implementation
}

func (fs *customFS) Mkdir(ctx context.Context, name string, perm os.FileMode) error {
    // Implementation
    return nil
}

func (fs *customFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
    // Implementation
    return nil, nil
}

func (fs *customFS) RemoveAll(ctx context.Context, name string) error {
    // Implementation
    return nil
}

func (fs *customFS) Rename(ctx context.Context, oldName, newName string) error {
    // Implementation
    return nil
}

func (fs *customFS) Stat(ctx context.Context, name string) (os.FileInfo, error) {
    // Implementation
    return nil, nil
}

func startCustomWebDAV() error {
    handler := &webdav.Handler{
        FileSystem: &customFS{},
        LockSystem: webdav.NewMemLS(),
    }

    return http.ListenAndServe(":8080", handler)
}