diff --git a/gns3server/api/middlewares.py b/gns3server/api/middlewares.py deleted file mode 100644 index 48f84e34..00000000 --- a/gns3server/api/middlewares.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2020 GNS3 Technologies Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import time -from starlette.types import ASGIApp, Message, Receive, Scope, Send -from gns3server.version import __version__ - - -class AddExtraHeadersMiddleware: - - def __init__(self, app: ASGIApp) -> None: - self.app = app - - async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: - - - if scope["type"] in ("http", "websocket") and scope["scheme"] in ("http", "ws"): - url = URL(scope=scope) - redirect_scheme = {"http": "https", "ws": "wss"}[url.scheme] - netloc = url.hostname if url.port in (80, 443) else url.netloc - url = url.replace(scheme=redirect_scheme, netloc=netloc) - response = RedirectResponse(url, status_code=307) - await response(scope, receive, send) - - -@app.middleware("http") -async def add_extra_headers(request: Request, call_next): - start_time = time.time() - response = await call_next(request) - process_time = time.time() - start_time - response.headers["X-Process-Time"] = str(process_time) - response.headers["X-GNS3-Server-Version"] = "{}".format(__version__) - return response diff --git a/gns3server/endpoints/compute/__init__.py b/gns3server/api/routes/compute/__init__.py similarity index 98% rename from gns3server/endpoints/compute/__init__.py rename to gns3server/api/routes/compute/__init__.py index 42f8b066..c9734739 100644 --- a/gns3server/endpoints/compute/__init__.py +++ b/gns3server/api/routes/compute/__init__.py @@ -20,7 +20,7 @@ from fastapi.responses import JSONResponse from starlette.exceptions import HTTPException as StarletteHTTPException from gns3server.controller.gns3vm.gns3_vm_error import GNS3VMError from gns3server.compute.error import ImageMissingError, NodeError -from gns3server.ubridge.ubridge_error import UbridgeError +from gns3server.compute.ubridge.ubridge_error import UbridgeError from gns3server.compute.compute_error import ( ComputeError, diff --git a/gns3server/endpoints/__init__.py b/gns3server/db/__init__.py similarity index 100% rename from gns3server/endpoints/__init__.py rename to gns3server/db/__init__.py