-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from mariux64/plprj-v2.16.3
plprj v2.16.3
- Loading branch information
Showing
12 changed files
with
352 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ | |
*.tar.xz | ||
!/*.patch | ||
!/*.sh | ||
/t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
diff --git a/src/paperless/asgi.py b/src/paperless/asgi.py | ||
index 8d63c347a..45d8daa3a 100644 | ||
--- a/src/paperless/asgi.py | ||
+++ b/src/paperless/asgi.py | ||
@@ -1,13 +1,134 @@ | ||
import os | ||
|
||
-from django.core.asgi import get_asgi_application | ||
+# from django.core.asgi import get_asgi_application | ||
+ | ||
+import django | ||
+from django.core.handlers.asgi import ASGIHandler | ||
+ | ||
+# https://code.djangoproject.com/ticket/36399 | ||
+assert django.VERSION < (6,0), "Remove ASGIRequest backport." | ||
+ | ||
+class XXXASGIRequest(HttpRequest): | ||
+ """ | ||
+ Custom request subclass that decodes from an ASGI-standard request dict | ||
+ and wraps request body handling. | ||
+ """ | ||
+ | ||
+ # Number of seconds until a Request gives up on trying to read a request | ||
+ # body and aborts. | ||
+ body_receive_timeout = 60 | ||
+ | ||
+ def __init__(self, scope, body_file): | ||
+ self.scope = scope | ||
+ self._post_parse_error = False | ||
+ self._read_started = False | ||
+ self.resolver_match = None | ||
+ self.path = scope["path"] | ||
+ self.script_name = get_script_prefix(scope) | ||
+ if self.script_name: | ||
+ # TODO: Better is-prefix checking, slash handling? | ||
+ self.path_info = scope["path"].removeprefix(self.script_name) | ||
+ else: | ||
+ self.path_info = scope["path"] | ||
+ # HTTP basics. | ||
+ self.method = self.scope["method"].upper() | ||
+ # Ensure query string is encoded correctly. | ||
+ query_string = self.scope.get("query_string", "") | ||
+ if isinstance(query_string, bytes): | ||
+ query_string = query_string.decode() | ||
+ self.META = { | ||
+ "REQUEST_METHOD": self.method, | ||
+ "QUERY_STRING": query_string, | ||
+ "SCRIPT_NAME": self.script_name, | ||
+ "PATH_INFO": self.path_info, | ||
+ # WSGI-expecting code will need these for a while | ||
+ "wsgi.multithread": True, | ||
+ "wsgi.multiprocess": True, | ||
+ } | ||
+ if self.scope.get("client"): | ||
+ self.META["REMOTE_ADDR"] = self.scope["client"][0] | ||
+ self.META["REMOTE_HOST"] = self.META["REMOTE_ADDR"] | ||
+ self.META["REMOTE_PORT"] = self.scope["client"][1] | ||
+ if self.scope.get("server"): | ||
+ self.META["SERVER_NAME"] = self.scope["server"][0] | ||
+ self.META["SERVER_PORT"] = str(self.scope["server"][1]) | ||
+ else: | ||
+ self.META["SERVER_NAME"] = "unknown" | ||
+ self.META["SERVER_PORT"] = "0" | ||
+ # Headers go into META. | ||
+ for name, value in self.scope.get("headers", []): | ||
+ name = name.decode("latin1") | ||
+ if name == "content-length": | ||
+ corrected_name = "CONTENT_LENGTH" | ||
+ elif name == "content-type": | ||
+ corrected_name = "CONTENT_TYPE" | ||
+ else: | ||
+ corrected_name = "HTTP_%s" % name.upper().replace("-", "_") | ||
+ # HTTP/2 say only ASCII chars are allowed in headers, but decode | ||
+ # latin1 just in case. | ||
+ value = value.decode("latin1") | ||
+ if corrected_name == "HTTP_COOKIE": | ||
+ existing = self.META.get("HTTP_COOKIE") | ||
+ if existing is not None: | ||
+ value = existing + value | ||
+ self.META["HTTP_COOKIE"] = value | ||
+ else: | ||
+ if corrected_name in self.META: | ||
+ value = self.META[corrected_name] + "," + value | ||
+ self.META[corrected_name] = value | ||
+ # Pull out request encoding, if provided. | ||
+ self._set_content_type_params(self.META) | ||
+ # Directly assign the body file to be our stream. | ||
+ self._stream = body_file | ||
+ # Other bits. | ||
+ self.resolver_match = None | ||
+ | ||
+ @cached_property | ||
+ def GET(self): | ||
+ return QueryDict(self.META["QUERY_STRING"]) | ||
+ | ||
+ def _get_scheme(self): | ||
+ return self.scope.get("scheme") or super()._get_scheme() | ||
+ | ||
+ def _get_post(self): | ||
+ if not hasattr(self, "_post"): | ||
+ self._load_post_and_files() | ||
+ return self._post | ||
+ | ||
+ def _set_post(self, post): | ||
+ self._post = post | ||
+ | ||
+ def _get_files(self): | ||
+ if not hasattr(self, "_files"): | ||
+ self._load_post_and_files() | ||
+ return self._files | ||
+ | ||
+ POST = property(_get_post, _set_post) | ||
+ FILES = property(_get_files) | ||
+ | ||
+ @cached_property | ||
+ def COOKIES(self): | ||
+ return parse_cookie(self.META.get("HTTP_COOKIE", "")) | ||
+ | ||
+ def close(self): | ||
+ super().close() | ||
+ self._stream.close() | ||
+ | ||
+ | ||
+class BackportASGIHandler(ASGIHandler): | ||
+ request_class = XXXASGIHandler | ||
+ | ||
|
||
# Fetch Django ASGI application early to ensure AppRegistry is populated | ||
# before importing consumers and AuthMiddlewareStack that may import ORM | ||
# models. | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "paperless.settings") | ||
-django_asgi_app = get_asgi_application() | ||
+# django_asgi_app = get_asgi_application() | ||
+ | ||
+django.setup(set_prefix=False) | ||
+ | ||
+application = BackportASGIHandler() | ||
|
||
from channels.auth import AuthMiddlewareStack # noqa: E402 | ||
from channels.routing import ProtocolTypeRouter # noqa: E402 |
Oops, something went wrong.