mar10/wsgidav

Wishlist: example/support for redirection to online (http/https) resources

yarikoptic opened this issue · 5 comments

To a degree it is a reincarnated

It would have been great if there was a sample Provider (and whatever it takes) for a WebDAV server which overall is a simple redirection service to some other http or https website, and assuming some default indexes (e.g. as provided by apache), so it could have config like

          "provider_mapping": {
            "/dav": HTTPRedirectionProvider("https://example.com/someprefix/"),
        },

and have /dav/path/file be redirected to https://example.com/someprefix/path/file.

Alternative possibly immediately useful example which could be sufficient to demonstrate ability to redirect, would be to redirect to S3, assuming that permissions allow for listing of the prefix to discover underlying "directories/" (there are no directories on S3 per se). S3 also has support/semantics for COPY and MOVE so there could be those implemented/supported as well, so making it not only read-only.

This would provide a good example on how to establish any other redirection service where corresponding mapping could be more involved, e.g. relying on obtaining target URLs through some API etc.

@yarikoptic - at a proof-of-concept level, I think one could override the do_GET method in wsgidav.request_server.RequestServer to do a targeted redirect based on path. Not a great long-term solution but it'd allow you to get passed the current speedbump of redirects to see if the rest of the idea works.

@bbockelm How would one do that while using wsgidav as a library (via the normal WsgiDAVApp(config) interface) with a custom provider?

@jwodder - I don't think you can do it cleanly like that. That's why I said the suggestion would be a proof-of-concept / not great long-term. E.g., you'd have to reproduce the logic around here:

app = RequestServer(provider)

and then adding the resolver as middleware as in here:

RequestResolver, # this must be the last middleware item

@mar10 et alii: I'm interested in submitting a PR that would add support for redirects, and my main question at the moment is what sort of public API you'd like added to dav_provider.py to enable this. I've come up with the following design:

  • Add a Redirect class with url: str and status_code: int (default = 302) fields
  • Add the following methods to DAVNonCollection:
    • is_redirect(self) -> bool — When this returns True, it signifies that requests to the resource should be redirected to the return value of get_redirect().
      • The default implementation returns self.get_redirect() is not None
    • get_redirect(self) -> Redirect | None
      • The default implementation returns None
    • If is_redirect() returns true, then get_content() can do anything, including erroring or returning None. Other methods remain unaltered.
  • I've opted not to add these methods to _DAVResource, as allowing collections to be redirects seems like it would come with a whole bunch of implementation issues.

Thoughts?

mar10 commented

How would you implement get_content_length(), get_content_type, get_etag, etc. in these cases?

Maybe it would be better to open a discussion and detail the user story for this.