Skip to content

proposal: add a context argument to webdav.FileSystem methods #17658

@kardianos

Description

@kardianos

Proposed Change

In the package golang.org/x/net/webdav there is currently no way to pass request specific parameters from the webdav request to the FileSystem interface. If the FileSystem methods took a context parameter such parameters and request scoped parameters could be put in the context. The context value would come from the http.Request.Context() method when available.

So this:

type FileSystem interface {
    Mkdir(name string, perm os.FileMode) error
    OpenFile(name string, flag int, perm os.FileMode) (File, error)
    RemoveAll(name string) error
    Rename(oldName, newName string) error
    Stat(name string) (os.FileInfo, error)
}

would turn into this:

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

Examples of where this is useful

  • Authenticate the username and password from a webdav request and provide file level authentication or remote authentication to the FileSystem.
  • If a webdav request is initiated but cancelled or the connection is dropped, any subsequent operations, esp remote operations or copy operations on large files, could be also cancelled.

Other Options

I'm not aware of any viable workarounds that would work today that could pass request specific information to the FileSystem operations. The FileSystem interface is provided to the webdav.Handler so there is no way to create some type of closure that returns a request scoped properties. Nor would you want to create an ad-hoc webdav.Handler as that would defeat the lock system.

Compatibility

This would break any custom FileSystem implementations. However updating to be compatible is trivial, just adding a context argument to file methods.

On go1.7+ the context argument would be supplied by http.Request.Context() and on eailier versions the context method would come from golang.org/x/net/context.Background(). When go1.6 support is dropped from the builders the internal xml package and the background context shim can be dropped.

/cc @nigeltao @adg

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions