Skip to content
Snippets Groups Projects
Commit 8cac60be authored by Andrea Grazioso (agr-odoo)'s avatar Andrea Grazioso (agr-odoo)
Browse files

[FIX] http: disable cache-control header (debug) for wkhtmltopdf

Activate developer mode, generate a report (print an invoice)

The report will have missing pieces, like the footer or some part of the
header. This is probably caused by wkhtmltopdf not loading properly some
resources

Wkhtmtopdf generate the same warning message for every problematic resource:
"Warning: Received createRequest signal on a disposed ResourceObject's
NetworkAccessManager. This might be an indication of an iframe taking
too long to load."

Related issue on wkhtmltopdf project page:
wkhtmltopdf/wkhtmltopdf#1865
wkhtmltopdf/wkhtmltopdf#3933
wkhtmltopdf/wkhtmltopdf#2565

The problem is located in the response that wkhtmltopdf receive:
in debug mode the header of the response contains
'Cache-Control: no-cache' which probably create a race condition during
the rendering while a second request is attempted to verify the
resources.

Adding a raw user agent check to not include this header directive
fix the problem

Notes from odony:

We've considered some alternative solutions to preserve the purpose of the
DisableCacheMiddleware without having to explicitly test for wkhtmltopdf.

* 'Cache-Control: no-cache' (current behavior) breaks wkhtmltopdf rendering
* 'Cache-Control: no-store' breaks wkhtmltopdf rendering too
* 'Cache-Control: max-age=0' breaks wkhtmltopdf rendering too. It works
when increasing the delay to a few seconds, but no magic value will work
for very long documents, or it will stop serving its purpose, so it's not a
viable option.
* 'Cache-Control: must-revalidate' does not break wkhtmltopdf rendering (no
duplicate requests at all), but it is not clear from the RFC
(https://tools.ietf.org/html/rfc7234#section-5.2.2.1

) that it
will have the intended effect for our middlewar

opw-2086708

Closes #38394

closes odoo/odoo#39236

Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent fb914d17
No related branches found
No related tags found
No related merge requests found
......@@ -1238,7 +1238,7 @@ class DisableCacheMiddleware(object):
def start_wrapped(status, headers):
req = werkzeug.wrappers.Request(environ)
root.setup_session(req)
if req.session and req.session.debug:
if req.session and req.session.debug and not 'wkhtmltopdf' in req.headers.get('User-Agent'):
new_headers = [('Cache-Control', 'no-cache')]
for k, v in headers:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment