Sunday, July 28, 2019

truncated response content in middleware

from django.conf import settings
from django.http import HttpResponse
import subprocess

# =====================================================================================
class PrerenderingMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
# One-time configuration and initialization.

def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.

response = self.get_response(request)

html = response.content

print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
print(html) # this is somehow strangely truncated
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")

ret = subprocess.run([ 'node', './prerending.js' ], input = html, capture_output = True) # process the javascript in the page

response = HttpResponse(ret.stdout)
return reponse

Hi,

i'm trying to build my own middleware for server side javascript
prerending. It's currently very simple (see attachment). It seems to be
working fine for few pages but for some other pages the reponse.content
is somehow truncated (line 20). The reponse.content is truncated at
exactly 4096 bytes. Is there some size limit to the reponse that is
processed at a time? Can i somehow process the whole response?

cheers,
Vaclav
--
Václav Mach
tel: +420 234 680 206
CESNET, z.s.p.o.
www.cesnet.cz

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2d292c0f-e70b-7fca-e719-039f3b59c197%40cesnet.cz.

No comments:

Post a Comment