diff --git a/apps/common/middleware/doc_headers_middleware.py b/apps/common/middleware/doc_headers_middleware.py new file mode 100644 index 000000000..4024e6ddb --- /dev/null +++ b/apps/common/middleware/doc_headers_middleware.py @@ -0,0 +1,62 @@ +# coding=utf-8 +""" + @project: maxkb + @Author:虎 + @file: static_headers_middleware.py + @date:2024/3/13 18:26 + @desc: +""" +from django.http import HttpResponse +from django.utils.deprecation import MiddlewareMixin + +content = """ + + + + + + + Document + + + + + +""" + + +class DocHeadersMiddleware(MiddlewareMixin): + def process_response(self, request, response): + if request.path.startswith('/doc/') or request.path.startswith('/doc/chat/'): + HTTP_REFERER = request.META.get('HTTP_REFERER') + if HTTP_REFERER is None: + return HttpResponse(content) + if HTTP_REFERER == request._current_scheme_host + request.path: + return response + return response