Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(webdav): align GET content length with response body (#4408)
Yu Zhang2898f267277c
diff --git a/openviking/server/routers/webdav.py b/openviking/server/routers/webdav.pyindex bd8da9d10..44678399d 100644--- a/openviking/server/routers/webdav.py+++ b/openviking/server/routers/webdav.py@@ -280,9 +280,10 @@ async def get_or_head(if stat.get("isDir", False):return _error(405, "GET is only supported for files")- body = b"" if request.method == "HEAD" else await service.fs.read_file_bytes(uri, ctx=_ctx)+ is_head = request.method == "HEAD"+ body = b"" if is_head else await service.fs.read_file_bytes(uri, ctx=_ctx)headers = _webdav_headers()- headers["Content-Length"] = str(int(stat.get("size", 0) or 0))+ headers["Content-Length"] = str(int(stat.get("size", 0) or 0) if is_head else len(body))last_modified = _http_last_modified(str(stat.get("modTime", "") or ""))if last_modified:headers["Last-Modified"] = last_modifieddiff --git a/tests/server/test_api_webdav.py b/tests/server/test_api_webdav.pyindex 8a10a822d..2da34222e 100644--- a/tests/server/test_api_webdav.py+++ b/tests/server/test_api_webdav.py@@ -6,7 +6,9 @@import xml.etree.ElementTree as ETimport httpx+from starlette.requests import Request+from openviking.server.routers import webdav as webdav_routerfrom openviking.server.routers.webdav import _ensure_exposed_path, _exposed_child_entriesfrom openviking_cli.exceptions import NotFoundError@@ -22,6 +24,40 @@ def _webdav_path_from_uri(uri: str) -> str:return uri[len(prefix) :].lstrip("/")+async def test_webdav_get_content_length_uses_delivered_body_size(monkeypatch):+ class FakeFS:+ async def stat(self, uri: str, ctx=None):+ assert uri == "viking://resources/scratch/notes.md"+ return {+ "isDir": False,+ "name": "notes.md",+ "size": len(b"hello") + 100,+ "modTime": "",+ }++ async def read_file_bytes(self, uri: str, ctx=None):+ assert uri == "viking://resources/scratch/notes.md"+ return b"hello"++ class FakeService:+ fs = FakeFS()++ monkeypatch.setattr(webdav_router, "get_service", lambda: FakeService())+ request = Request(+ {+ "type": "http",+ "method": "GET",+ "path": "/webdav/resources/scratch/notes.md",+ "headers": [],+ }+ )++ resp = await webdav_router.get_or_head(request, "scratch/notes.md", None)++ assert resp.body == b"hello"+ assert resp.headers["content-length"] == "5"++async def test_webdav_options_advertises_dav(client: httpx.AsyncClient):resp = await client.request("OPTIONS", "/webdav/resources")assert resp.status_code == 204@@ -112,6 +148,7 @@ async def test_webdav_put_create_get_and_replace_text_file(client: httpx.AsyncClget_resp = await client.get("/webdav/resources/scratch/notes.md")assert get_resp.status_code == 200assert get_resp.text == "# Notes\n\nhello"+ assert get_resp.headers["content-length"] == str(len(get_resp.content))replace_resp = await client.request("PUT",@@ -123,6 +160,7 @@ async def test_webdav_put_create_get_and_replace_text_file(client: httpx.AsyncClget_resp = await client.get("/webdav/resources/scratch/notes.md")assert get_resp.status_code == 200assert get_resp.text == "# Notes\n\nupdated"+ assert get_resp.headers["content-length"] == str(len(get_resp.content))async def test_webdav_put_replace_reuses_direct_write_path(