Closed davidbrochart closed 1 year ago
Yes, both! How can I help you?
Great, thanks for the feedback. How would it look like to serve the WebDAV routes inside an existing FastAPI application?
Sorry for the delay, I have some projects that must be done. I have added a example, maybe it helps you.
Sorry for the delay, I have some projects that must be done.
No worries!
I have added a example, maybe it helps you.
Thanks a lot!
I was wondering if it is possible to add asgi-webdav as a FastAPI middleware, instead of using the method described in the examples?
It's a good idea, I will try. But I'm not sure when to deal with it
Something like that should work:
from functools import partial
from asgi_webdav.constants import DAV_METHODS, AppEntryParameters
from asgi_webdav.server import get_asgi_app as get_webdav_asgi_app
from fastapi import FastAPI
webdav_config = {
"provider_mapping": [
{
"prefix": "/webdav",
"uri": "file://.",
},
]
}
webdav_aep = AppEntryParameters()
webdav_app = get_webdav_asgi_app(aep=webdav_aep, config_obj=webdav_config)
class WebDAVApp:
def __init__(self, app, webdav_app):
self._app = app
self._webdav_app = webdav_app
async def __call__(self, scope, receive, send):
if scope.get("method") in DAV_METHODS and scope.get("path").startswith("/webdav"):
return await self._webdav_app(scope, receive, send)
return await self._app(scope, receive, send)
app = FastAPI()
app.add_middleware(partial(WebDAVApp, webdav_app=webdav_app))
Nice! Welcome PR
Done in #30.
I'm new to WebDAV, but seeing that asgi-webdav is built on top of ASGI, does it mean that it could work with FastAPI? Or is it an entirely separate server?