mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 16:28:11 +00:00
parent
3680c40e23
commit
6b862b8397
@ -30,10 +30,11 @@ renderer = jinja2.Environment(loader=jinja2.PackageLoader('gns3server', 'templat
|
|||||||
|
|
||||||
class Response(aiohttp.web.Response):
|
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._route = route
|
||||||
self._output_schema = output_schema
|
self._output_schema = output_schema
|
||||||
|
self._request = request
|
||||||
headers['X-Route'] = self._route
|
headers['X-Route'] = self._route
|
||||||
headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__)
|
headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__)
|
||||||
super().__init__(headers=headers, **kwargs)
|
super().__init__(headers=headers, **kwargs)
|
||||||
@ -70,6 +71,7 @@ class Response(aiohttp.web.Response):
|
|||||||
"""
|
"""
|
||||||
template = renderer.get_template(template_filename)
|
template = renderer.get_template(template_filename)
|
||||||
kwargs["gns3_version"] = __version__
|
kwargs["gns3_version"] = __version__
|
||||||
|
kwargs["gns3_host"] = self._request.host
|
||||||
self.html(template.render(**kwargs))
|
self.html(template.render(**kwargs))
|
||||||
|
|
||||||
def json(self, answer):
|
def json(self, answer):
|
||||||
|
@ -120,7 +120,7 @@ class Route(object):
|
|||||||
|
|
||||||
# Non API call
|
# Non API call
|
||||||
if api_version is None:
|
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)
|
yield from func(request, response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ -136,34 +136,34 @@ class Route(object):
|
|||||||
f.write("\n")
|
f.write("\n")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.warn("Could not write to the record file {}: {}".format(record_file, 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)
|
yield from func(request, response)
|
||||||
except aiohttp.web.HTTPBadRequest as e:
|
except aiohttp.web.HTTPBadRequest as e:
|
||||||
response = Response(route=route)
|
response = Response(request=request, route=route)
|
||||||
response.set_status(e.status)
|
response.set_status(e.status)
|
||||||
response.json({"message": e.text, "status": e.status, "path": route, "request": request.json})
|
response.json({"message": e.text, "status": e.status, "path": route, "request": request.json})
|
||||||
except aiohttp.web.HTTPException as e:
|
except aiohttp.web.HTTPException as e:
|
||||||
response = Response(route=route)
|
response = Response(request=request, route=route)
|
||||||
response.set_status(e.status)
|
response.set_status(e.status)
|
||||||
response.json({"message": e.text, "status": e.status})
|
response.json({"message": e.text, "status": e.status})
|
||||||
except VMError as e:
|
except VMError as e:
|
||||||
log.error("VM error detected: {type}".format(type=type(e)), exc_info=1)
|
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.set_status(409)
|
||||||
response.json({"message": str(e), "status": 409})
|
response.json({"message": str(e), "status": 409})
|
||||||
except asyncio.futures.CancelledError as e:
|
except asyncio.futures.CancelledError as e:
|
||||||
log.error("Request canceled")
|
log.error("Request canceled")
|
||||||
response = Response(route=route)
|
response = Response(request=request, route=route)
|
||||||
response.set_status(408)
|
response.set_status(408)
|
||||||
response.json({"message": "Request canceled", "status": 408})
|
response.json({"message": "Request canceled", "status": 408})
|
||||||
except aiohttp.ClientDisconnectedError:
|
except aiohttp.ClientDisconnectedError:
|
||||||
log.error("Client disconnected")
|
log.error("Client disconnected")
|
||||||
response = Response(route=route)
|
response = Response(request=request, route=route)
|
||||||
response.set_status(408)
|
response.set_status(408)
|
||||||
response.json({"message": "Client disconnected", "status": 408})
|
response.json({"message": "Client disconnected", "status": 408})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("Uncaught exception detected: {type}".format(type=type(e)), exc_info=1)
|
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)
|
response.set_status(500)
|
||||||
CrashReport.instance().capture_exception(request)
|
CrashReport.instance().capture_exception(request)
|
||||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||||
|
Loading…
Reference in New Issue
Block a user