rexzhang / asgi-webdav

An asynchronous WebDAV server implementation, Support multi-provider, multi-account and permission control.
https://rexzhang.github.io/asgi-webdav/
MIT License
75 stars 14 forks source link

Running Webdav ASGI app under a sub-path #50

Open amundhov opened 4 months ago

amundhov commented 4 months ago

When I tried to follow the examples using asgi-webdav as middleware for another app I struggled a bit. I wanted to put webdev under the path "/resources" and keep all other top level paths for my main ASGI app.

What worked following work_as_fastapi_middleware.py :

Issues:

I think the core issue is asgi-webdav assumes that the requests it receives are always under the root "/" path. The ASGI specification provides root_path in the connection scope of its HTTP requests; This can be used to

  1. Properly map the request path into the relative paths of the webdav app (used to match providers and user permissions)
  2. Put back the root_path prefix on any internal links to webdav resources in the responses (href paths etc).

With properroot_path handling webdav app should just do the right thing and work in the following settings:

As FastAPI sub application: `from fastapi import FastAPI from asgi_webdav.server import get_asgi_app

app = FastAPI()

webdav_app = get_asgi_app() app.mount("/resources", webdav_app) `

Instructed by ASGI server to run at specified root_path: hypercorn --root-path "/resources" "webdav_app:webdav_app"

I have a PR coming for suggesting a way to do the root_path handling.

rexzhang commented 4 months ago

wellcome PR