summaryrefslogtreecommitdiff
path: root/talerbank
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-05-16 17:56:51 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-05-16 17:56:51 +0200
commit25f077c30108e15ad3b9e9290db0e665e4b042fb (patch)
treef73ff5dd781c41f77bfea4df23a62dfe3e59c982 /talerbank
parent9b04f8ca087df164dc8abda7d9339ab2b3ca9b60 (diff)
downloadbank-25f077c30108e15ad3b9e9290db0e665e4b042fb.tar.gz
bank-25f077c30108e15ad3b9e9290db0e665e4b042fb.tar.bz2
bank-25f077c30108e15ad3b9e9290db0e665e4b042fb.zip
Decompression middleware.
Diffstat (limited to 'talerbank')
-rw-r--r--talerbank/app/middleware.py34
-rw-r--r--talerbank/settings.py1
2 files changed, 35 insertions, 0 deletions
diff --git a/talerbank/app/middleware.py b/talerbank/app/middleware.py
index 371d9b6..138e509 100644
--- a/talerbank/app/middleware.py
+++ b/talerbank/app/middleware.py
@@ -1,4 +1,5 @@
import logging
+import zlib
from django.http import JsonResponse
from django.shortcuts import redirect
from .models import BankAccount, BankTransaction
@@ -16,6 +17,39 @@ LOGGER = logging.getLogger()
##
+# Class decompressing requests.
+class DecompressionMiddleware:
+
+ ##
+ # Init constructor.
+ #
+ # @param self the object itself.
+ # @param get_response a Django-provided callable that calls
+ # whatever comes next in the chain: a further middleware
+ # or the view itself (please refer to the official
+ # documentation for more details).
+ def __init__(self, get_response):
+ self.get_response = get_response
+
+ ##
+ # This function is transparently invoked by Django when
+ # a request traverses the chain made of middleware classes
+ # and the view itself as the last element in the chain.
+ #
+ # Here happens the decompression.
+ #
+ # @param self this class.
+ # @param request Django-specific request object (of the same
+ # type that is handed to views).
+ # @return Django-specific response object.
+ def __call__(self, request):
+ print("Decompri?")
+ if "deflate" == request.headers.get("Content-Encoding"):
+ request._body = zlib.decompress(request.body)
+
+ return self.get_response(request)
+
+##
# Class holding data needed by the handling logic.
class ExceptionMiddleware:
diff --git a/talerbank/settings.py b/talerbank/settings.py
index 539843b..f3f099d 100644
--- a/talerbank/settings.py
+++ b/talerbank/settings.py
@@ -77,6 +77,7 @@ MIDDLEWARE = [
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'talerbank.app.middleware.ExceptionMiddleware',
+ 'talerbank.app.middleware.DecompressionMiddleware'
]
TEMPLATES = [