From 5585ed74b0116deb2fe8522e7d3afdd3ee639ceb Mon Sep 17 00:00:00 2001 From: Alexander Chabo Date: Thu, 12 Jan 2023 16:50:35 +0100 Subject: [PATCH 1/4] Add status code 404 as ok --- rendertron/middleware/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rendertron/middleware/base.py b/rendertron/middleware/base.py index fa097e9..54a413f 100644 --- a/rendertron/middleware/base.py +++ b/rendertron/middleware/base.py @@ -72,7 +72,7 @@ def render_url(self, url, request): try: with urlopen(proxy_url) as response: - if response.code == 200: # What about other 'ok' codes? + if response.code in [200, 404]: data = response.read() # Should we store the response code, headers etc? metas = ["code", "reason", "status"] From e7ee0d988ce210feafd3a4391e4ac09f4a6fcc7b Mon Sep 17 00:00:00 2001 From: Alexander Chabo Date: Fri, 13 Jan 2023 14:38:52 +0100 Subject: [PATCH 2/4] Dont check status --- rendertron/middleware/base.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rendertron/middleware/base.py b/rendertron/middleware/base.py index 54a413f..21d4d17 100644 --- a/rendertron/middleware/base.py +++ b/rendertron/middleware/base.py @@ -72,13 +72,12 @@ def render_url(self, url, request): try: with urlopen(proxy_url) as response: - if response.code in [200, 404]: - data = response.read() - # Should we store the response code, headers etc? - metas = ["code", "reason", "status"] - meta = {key: getattr(response, key) for key in metas} - self.storage.store_response(request, data, meta) - return data, meta + data = response.read() + # Should we store the response code, headers etc? + metas = ["code", "reason", "status"] + meta = {key: getattr(response, key) for key in metas} + self.storage.store_response(request, data, meta) + return data, meta except Exception: pass return None, None From 2a38a151cfd725b1e68703e6b340437ed2f87731 Mon Sep 17 00:00:00 2001 From: Alexander Chabo Date: Fri, 13 Jan 2023 15:11:05 +0100 Subject: [PATCH 3/4] Change name to status_code --- rendertron/middleware/base.py | 2 +- rendertron/middleware/django.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rendertron/middleware/base.py b/rendertron/middleware/base.py index 21d4d17..3e86f94 100644 --- a/rendertron/middleware/base.py +++ b/rendertron/middleware/base.py @@ -74,7 +74,7 @@ def render_url(self, url, request): with urlopen(proxy_url) as response: data = response.read() # Should we store the response code, headers etc? - metas = ["code", "reason", "status"] + metas = ["content_type", "status_code", "reason", "charset"] meta = {key: getattr(response, key) for key in metas} self.storage.store_response(request, data, meta) return data, meta diff --git a/rendertron/middleware/django.py b/rendertron/middleware/django.py index 321122e..ad7f166 100644 --- a/rendertron/middleware/django.py +++ b/rendertron/middleware/django.py @@ -84,9 +84,9 @@ def __call__(self, request): if content is not None: # possible keyword arguments of HttpResponse - kwargs = ["content_type", "status", "reason", "charset"] + metas = ["content_type", "status_code", "reason", "charset"] return HttpResponse( - content=content, **{key: meta[key] for key in meta if key in kwargs} + content=content, **{key: meta[key] for key in meta if key in metas} ) # No rendered response was returned, continue as normal: From 4991aab97a1437a7aaff5c93c9693e6897c2a86f Mon Sep 17 00:00:00 2001 From: Alexander Chabo Date: Fri, 13 Jan 2023 15:25:26 +0100 Subject: [PATCH 4/4] Test --- rendertron/middleware/base.py | 3 ++- rendertron/middleware/django.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rendertron/middleware/base.py b/rendertron/middleware/base.py index 3e86f94..efe284d 100644 --- a/rendertron/middleware/base.py +++ b/rendertron/middleware/base.py @@ -73,8 +73,9 @@ def render_url(self, url, request): try: with urlopen(proxy_url) as response: data = response.read() + print("hello", data) # Should we store the response code, headers etc? - metas = ["content_type", "status_code", "reason", "charset"] + metas = ["code", "reason", "status"] meta = {key: getattr(response, key) for key in metas} self.storage.store_response(request, data, meta) return data, meta diff --git a/rendertron/middleware/django.py b/rendertron/middleware/django.py index ad7f166..321122e 100644 --- a/rendertron/middleware/django.py +++ b/rendertron/middleware/django.py @@ -84,9 +84,9 @@ def __call__(self, request): if content is not None: # possible keyword arguments of HttpResponse - metas = ["content_type", "status_code", "reason", "charset"] + kwargs = ["content_type", "status", "reason", "charset"] return HttpResponse( - content=content, **{key: meta[key] for key in meta if key in metas} + content=content, **{key: meta[key] for key in meta if key in kwargs} ) # No rendered response was returned, continue as normal: