webdav

package
v0.0.0-...-642df0c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package webdav provides a WebDAV server implementation.

Index

Constants

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

http://www.webdav.org/specs/rfc4918.html#status.code.extensions.to.http11

Variables

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

ErrNotImplemented should be returned by optional interfaces if they want the original implementation to be used.

Functions

func StatusText

func StatusText(code int) string

Types

type Condition

type Condition struct {
	Not   bool
	Token string
	ETag  string
}

---- from: lock.go Condition can match a WebDAV resource, based on a token or ETag. Exactly one of Token and ETag should be non-empty.

type ContentTyper

type ContentTyper interface {
	// ContentType returns the content type for the file.
	//
	// If this returns error ErrNotImplemented then the error will
	// be ignored and the base implementation will be used
	// instead.
	ContentType(ctx context.Context) (string, error)
}

ContentTyper is an optional interface for the os.FileInfo objects returned by the FileSystem.

If this interface is defined then it will be used to read the content type from the object.

If this interface is not defined the file will be opened and the content type will be guessed from the initial contents of the file.

type DeadPropsHolder

type DeadPropsHolder interface {
	// DeadProps returns a copy of the dead properties held.
	DeadProps() (map[xml.Name]Property, error)

	// Patch patches the dead properties held.
	//
	// Patching is atomic; either all or no patches succeed. It returns (nil,
	// non-nil) if an internal server error occurred, otherwise the Propstats
	// collectively contain one Property for each proposed patch Property. If
	// all patches succeed, Patch returns a slice of length one and a Propstat
	// element with a 200 OK HTTP status code. If none succeed, for reasons
	// other than an internal server error, no Propstat has status 200 OK.
	//
	// For more details on when various HTTP status codes apply, see
	// http://www.webdav.org/specs/rfc4918.html#PROPPATCH-status
	Patch([]Proppatch) ([]Propstat, error)
}

DeadPropsHolder holds the dead properties of a resource.

Dead properties are those properties that are explicitly defined. In comparison, live properties, such as DAV:getcontentlength, are implicitly defined by the underlying resource, and cannot be explicitly overridden or removed. See the Terminology section of http://www.webdav.org/specs/rfc4918.html#rfc.section.3

There is a whitelist of the names of live properties. This package handles all live properties, and will only pass non-whitelisted names to the Patch method of DeadPropsHolder implementations.

type Dir

type Dir string

A Dir implements FileSystem using the native file system restricted to a specific directory tree.

While the FileSystem.OpenFile method takes '/'-separated paths, a Dir's string value is a filename on the native file system, not a URL, so it is separated by filepath.Separator, which isn't necessarily '/'.

An empty Dir is treated as ".".

func (Dir) Mkdir

func (d Dir) Mkdir(ctx context.Context, name string, perm os.FileMode) error

func (Dir) OpenFile

func (d Dir) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error)

func (Dir) RemoveAll

func (d Dir) RemoveAll(ctx context.Context, name string) error

func (Dir) Rename

func (d Dir) Rename(ctx context.Context, oldName, newName string) error

func (Dir) Stat

func (d Dir) Stat(ctx context.Context, name string) (os.FileInfo, error)

type ETager

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)
}

ETager is an optional interface for the os.FileInfo objects returned by the FileSystem.

If this interface is defined then it will be used to read the ETag for the object.

If this interface is not defined an ETag will be computed using the ModTime() and the Size() methods of the os.FileInfo object.

type File

type File interface {
	http.File
	io.Writer
}

A File is returned by a FileSystem's OpenFile method and can be served by a Handler.

A File may optionally implement the DeadPropsHolder interface, if it can load and save dead properties.

type FileSystem

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)
}

A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.

Each method has the same semantics as the os package's function of the same name.

Note that the os.Rename documentation says that "OS-specific restrictions might apply". In particular, whether or not renaming a file or directory overwriting another existing file or directory is an error is OS-dependent.

type Handler

type Handler struct {
	// Prefix is the URL path prefix to strip from WebDAV resource paths.
	Prefix string
	// FileSystem is the virtual file system.
	FileSystem FileSystem
	// Logger is an optional error logger. If non-nil, it will be called
	// for all HTTP requests.
	Logger func(*http.Request, error)
}

func (*Handler) ServeHTTP

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

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

type Property

type Property struct {
	// XMLName is the fully qualified name that identifies this property.
	XMLName xml.Name

	// Lang is an optional xml:lang attribute.
	Lang string `xml:"xml:lang,attr,omitempty"`

	// InnerXML contains the XML representation of the property value.
	// See http://www.webdav.org/specs/rfc4918.html#property_values
	//
	// Property values of complex type or mixed-content must have fully
	// expanded XML namespaces or be self-contained with according
	// XML namespace declarations. They must not rely on any XML
	// namespace declarations within the scope of the XML document,
	// even including the DAV: namespace.
	InnerXML []byte `xml:",innerxml"`
}

Property represents a single DAV resource property as defined in RFC 4918. See http://www.webdav.org/specs/rfc4918.html#data.model.for.resource.properties

type Proppatch

type Proppatch struct {
	// Remove specifies whether this patch removes properties. If it does not
	// remove them, it sets them.
	Remove bool
	// Props contains the properties to be set or removed.
	Props []Property
}

Proppatch describes a property update instruction as defined in RFC 4918. See http://www.webdav.org/specs/rfc4918.html#METHOD_PROPPATCH

type Propstat

type Propstat struct {
	// Props contains the properties for which Status applies.
	Props []Property

	// Status defines the HTTP status code of the properties in Prop.
	// Allowed values include, but are not limited to the WebDAV status
	// code extensions for HTTP/1.1.
	// http://www.webdav.org/specs/rfc4918.html#status.code.extensions.to.http11
	Status int

	// XMLError contains the XML representation of the optional error element.
	// XML content within this field must not rely on any predefined
	// namespace declarations or prefixes. If empty, the XML error element
	// is omitted.
	XMLError string

	// ResponseDescription contains the contents of the optional
	// responsedescription field. If empty, the XML element is omitted.
	ResponseDescription string
}

Propstat describes a XML propstat element as defined in RFC 4918. See http://www.webdav.org/specs/rfc4918.html#ELEMENT_propstat

Directories

Path Synopsis
internal
xml
Package xml implements a simple XML 1.0 parser that understands XML name spaces.
Package xml implements a simple XML 1.0 parser that understands XML name spaces.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL