From ef6351983cb1655da809632773a01379331a148c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 8 Feb 2012 16:14:25 +0100 Subject: [PATCH] Better management of redirect Some web browsers don't support correctly empty content. Others don't follow no-HTTP protocol in location header so we use http-equiv="Refresh". And finally show a simple link for very old web browsers. review233001 --- trytond/protocols/jsonrpc.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/trytond/protocols/jsonrpc.py b/trytond/protocols/jsonrpc.py index 3390925c64..194c8cb7f4 100644 --- a/trytond/protocols/jsonrpc.py +++ b/trytond/protocols/jsonrpc.py @@ -27,6 +27,10 @@ except ImportError: import json import base64 import encodings +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO def object_hook(dct): @@ -212,12 +216,36 @@ class SimpleJSONRPCRequestHandler(GZipRequestHandlerMixin, return False def send_tryton_url(self, path): - self.send_response(301) + self.send_response(300) hostname = CONFIG['hostname'] or unicode(socket.getfqdn(), 'utf8') hostname = '.'.join(encodings.idna.ToASCII(part) for part in hostname.split('.')) - self.send_header('Location', 'tryton://%s%s' % (hostname, path)) + values = { + 'hostname': hostname, + 'path': path, + } + content = StringIO() + content.write('') + content.write('' % values) + content.write('Moved') + content.write('') + content.write('') + content.write('

Moved

') + content.write('

This page has moved to ' + '' + 'tryton://%(hostname)s%(path)s.

' % values) + content.write('') + content.write('') + length = content.tell() + content.seek(0) + self.send_header('Location', 'tryton://%(hostname)s%(path)s' % values) + self.send_header('Content-type', 'text/html') + self.send_header('Content-Length', str(length)) self.end_headers() + self.copyfile(content, self.wfile) + content.close() class SecureJSONRPCRequestHandler(SimpleJSONRPCRequestHandler):