webdav

package module
v0.0.0-...-94aeea2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

WebDAV for Caddy

This package implements a simple WebDAV handler module for Caddy.

Requires Caddy 2+.

Syntax

webdav [<matcher>] {
	root <path>
	prefix <request-base-path>
}

Because this directive does not come standard with Caddy, you need to put the directive in order. The correct place is up to you, but usually putting it near the end works if no other terminal directives match the same requests. It's common to pair a webdav handler with a file_server, so ordering it just before is often a good choice:

{
	order webdav before file_server
}

Alternatively, you may use route to order it the way you want. For example:

localhost

root * /srv

route {
	rewrite /dav /dav/
	webdav /dav/* {
		prefix /dav
	}
	file_server
}

The prefix directive is optional but has to be used if a webdav share is used in combination with matchers or path manipulations. This is because webdav uses absolute paths in its response. There exist a similar issue when using reverse proxies, see The "subfolder problem", OR, "why can't I reverse proxy my app into a subfolder?".

webdav /some/path/match/* {
	root /path
	prefix /some/path/match
}

If you want to serve WebDAV and directory listing under same path (similar behaviour as in Apache and Nginx), you may use Request Matchers to filter out GET requests and pass those to file_server.

Example with authenticated WebDAV and directory listing under the same path:

@get method GET

route {
    basicauth {
        username hashed_password_base64
    }
    file_server @get browse
    webdav
}

Or, if you want to create a public listing, but keep WebDAV behind authentication:

@notget not method GET

route @notget {
    basicauth {
        username hashed_password_base64
    }
    webdav
}
file_server browse

Credit

Special thanks to @hacdias for making caddy-webdav for Caddy 1, from which this work is derived: https://github.com/hacdias/caddy-webdav

Documentation

Overview

Package webdav implements a WebDAV server handler module for Caddy.

Derived from work by Henrique Dias: https://github.com/hacdias/caddy-webdav

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WebDAV

type WebDAV struct {
	// The root directory out of which to serve files. If
	// not specified, `{http.vars.root}` will be used if
	// set; otherwise, the current directory is assumed.
	// Accepts placeholders.
	Root string `json:"root,omitempty"`

	// The base path prefix used to access the WebDAV share.
	// Should be used if one more more matchers are used with the
	// webdav directive and it's needed to let the webdav share know
	// what the request base path will be.
	// For example:
	// webdav /some/path/match/* {
	//   root /path
	//   prefix /some/path/match
	// }
	// Accepts placeholders.
	Prefix string `json:"prefix,omitempty"`
	// contains filtered or unexported fields
}

WebDAV implements an HTTP handler for responding to WebDAV clients.

func (WebDAV) CaddyModule

func (WebDAV) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*WebDAV) Provision

func (wd *WebDAV) Provision(ctx caddy.Context) error

Provision sets up the module.

func (WebDAV) ServeHTTP

func (wd WebDAV) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

func (*WebDAV) UnmarshalCaddyfile

func (wd *WebDAV) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile sets up the handler from Caddyfile tokens.

webdav [<matcher>] {
    root <path>
}

Jump to

Keyboard shortcuts

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