mholt / caddy-webdav

WebDAV handler module for Caddy
Apache License 2.0
226 stars 23 forks source link

There is no singleton of WebDAV. How can we be ensured that the WebDAV instantiated with parsing Caddyfile config will be the one seving HTTP() #52

Closed idavollen closed 1 week ago

idavollen commented 1 week ago

There is no singleton of WebDAV in your code, however, the new(WebDAV) has been called in many places, especially it's total out of control where the New() in ModuleInfo will be called.

// CaddyModule returns the Caddy module information.
func (WebDAV) CaddyModule() caddy.ModuleInfo {
    return caddy.ModuleInfo{
        ID:  "http.handlers.webdav",
        **New: func() caddy.Module { return new(WebDAV) },**
    }
}
// parseWebdav parses the Caddyfile tokens for the webdav directive.
func parseWebdav(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
    **wd := new(WebDAV)**
    err := wd.UnmarshalCaddyfile(h.Dispenser)
    if err != nil {
        return nil, err
    }
    return wd, nil
}

How can we ensure that the wd WebDAV serving the HTTP request should be the WebDAV instance containing the Caddyfile config for DAV?

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

mholt commented 1 week ago

I believe your question is being answered here: https://github.com/caddyserver/caddy/issues/6647 (correct me if I'm wrong and this is separate)

But in that issue, we will need to see the full code in order to really help. Bits and pieces aren't enough to put together.