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 :
Dispatching to the webdav app
First level collections by including /resources explicitly in the provider prefix
Issues:
The /resource prefix is duplicated in Webdav Config and the middleware/ASGI app configuration
User permissions and provider prefixes also need to include the "/resources" prefix.
Top-level directory listing does not work, since "/" is not mapped to a provider
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
Properly map the request path into the relative paths of the webdav app (used to match providers and user permissions)
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
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 connectionscope
of its HTTP requests; This can be used toroot_path
prefix on any internal links to webdav resources in the responses (href paths etc).With proper
root_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.