From 6b862b83979560ad57d2834a36a46ad9a247cea3 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Thu, 23 Apr 2015 14:31:36 +0200 Subject: [PATCH] Correctly show the host in templates Fix #157 --- gns3server/web/response.py | 4 +++- gns3server/web/route.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gns3server/web/response.py b/gns3server/web/response.py index 42112fa9..fc1b55de 100644 --- a/gns3server/web/response.py +++ b/gns3server/web/response.py @@ -30,10 +30,11 @@ renderer = jinja2.Environment(loader=jinja2.PackageLoader('gns3server', 'templat class Response(aiohttp.web.Response): - def __init__(self, route=None, output_schema=None, headers={}, **kwargs): + def __init__(self, request=None, route=None, output_schema=None, headers={}, **kwargs): self._route = route self._output_schema = output_schema + self._request = request headers['X-Route'] = self._route headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__) super().__init__(headers=headers, **kwargs) @@ -70,6 +71,7 @@ class Response(aiohttp.web.Response): """ template = renderer.get_template(template_filename) kwargs["gns3_version"] = __version__ + kwargs["gns3_host"] = self._request.host self.html(template.render(**kwargs)) def json(self, answer): diff --git a/gns3server/web/route.py b/gns3server/web/route.py index 0c5631f1..2f8fd0c9 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -120,7 +120,7 @@ class Route(object): # Non API call if api_version is None: - response = Response(route=route, output_schema=output_schema) + response = Response(request=request, route=route, output_schema=output_schema) yield from func(request, response) return response @@ -136,34 +136,34 @@ class Route(object): f.write("\n") except OSError as e: log.warn("Could not write to the record file {}: {}".format(record_file, e)) - response = Response(route=route, output_schema=output_schema) + response = Response(request=request, route=route, output_schema=output_schema) yield from func(request, response) except aiohttp.web.HTTPBadRequest as e: - response = Response(route=route) + response = Response(request=request, route=route) response.set_status(e.status) response.json({"message": e.text, "status": e.status, "path": route, "request": request.json}) except aiohttp.web.HTTPException as e: - response = Response(route=route) + response = Response(request=request, route=route) response.set_status(e.status) response.json({"message": e.text, "status": e.status}) except VMError as e: log.error("VM error detected: {type}".format(type=type(e)), exc_info=1) - response = Response(route=route) + response = Response(request=request, route=route) response.set_status(409) response.json({"message": str(e), "status": 409}) except asyncio.futures.CancelledError as e: log.error("Request canceled") - response = Response(route=route) + response = Response(request=request, route=route) response.set_status(408) response.json({"message": "Request canceled", "status": 408}) except aiohttp.ClientDisconnectedError: log.error("Client disconnected") - response = Response(route=route) + response = Response(request=request, route=route) response.set_status(408) response.json({"message": "Client disconnected", "status": 408}) except Exception as e: log.error("Uncaught exception detected: {type}".format(type=type(e)), exc_info=1) - response = Response(route=route) + response = Response(request=request, route=route) response.set_status(500) CrashReport.instance().capture_exception(request) exc_type, exc_value, exc_tb = sys.exc_info()