From 92588223eedf6a8984788b4fb525ee02888a4dfd Mon Sep 17 00:00:00 2001 From: gary-Shen Date: Tue, 7 Jan 2025 11:42:29 +0800 Subject: [PATCH] fix: no cache for html file --- .gitmodules | 5 ----- labelu/main.py | 10 +++++++--- 2 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index ac23d03a..00000000 --- a/.gitmodules +++ /dev/null @@ -1,5 +0,0 @@ -[submodule "frontend"] - path = frontend - url = https://github.com/opendatalab/labelU-frontend.git - branch = main - ignore = dirty \ No newline at end of file diff --git a/labelu/main.py b/labelu/main.py index 4d460e44..518c7a40 100644 --- a/labelu/main.py +++ b/labelu/main.py @@ -103,9 +103,13 @@ def __init__(self, *args: Any, **kwargs: Any): def file_response(self, *args: Any, **kwargs: Any) -> Response: resp = super().file_response(*args, **kwargs) - resp.headers.setdefault("Cache-Control", self.cachecontrol) - resp.headers.setdefault("Pragma", self.pragma) - resp.headers.setdefault("Expires", self.expires) + + # No cache for html files + if resp.media_type == "text/html": + resp.headers.setdefault("Cache-Control", self.cachecontrol) + resp.headers.setdefault("Pragma", self.pragma) + resp.headers.setdefault("Expires", self.expires) + return resp app.mount("", NoCacheStaticFiles(packages=["labelu.internal"], html=True))