mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Cleanup exceptions
This commit is contained in:
parent
bf618d321c
commit
83f2509cfe
@ -15,6 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
from ...web.route import Route
|
from ...web.route import Route
|
||||||
from ...schemas.file import FILE_STREAM_SCHEMA
|
from ...schemas.file import FILE_STREAM_SCHEMA
|
||||||
@ -28,17 +29,19 @@ class FileHandler:
|
|||||||
description="Stream a file from the server",
|
description="Stream a file from the server",
|
||||||
status_codes={
|
status_codes={
|
||||||
200: "File retrieved",
|
200: "File retrieved",
|
||||||
404: "File doesn't exist"
|
404: "File doesn't exist",
|
||||||
|
409: "Can't access to file"
|
||||||
},
|
},
|
||||||
input=FILE_STREAM_SCHEMA
|
input=FILE_STREAM_SCHEMA
|
||||||
)
|
)
|
||||||
def read(request, response):
|
def read(request, response):
|
||||||
|
response.enable_chunked_encoding()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(request.json.get("location"), "rb") as f:
|
with open(request.json.get("location"), "rb") as f:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
response.content_type = "application/octet-stream"
|
response.content_type = "application/octet-stream"
|
||||||
response.set_status(200)
|
response.set_status(200)
|
||||||
response.enable_chunked_encoding()
|
|
||||||
# Very important: do not send a content lenght otherwise QT close the connection but curl can consume the Feed
|
# Very important: do not send a content lenght otherwise QT close the connection but curl can consume the Feed
|
||||||
response.content_length = None
|
response.content_length = None
|
||||||
|
|
||||||
@ -51,4 +54,7 @@ class FileHandler:
|
|||||||
else:
|
else:
|
||||||
response.write(data)
|
response.write(data)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
response.set_status(404)
|
raise aiohttp.web.HTTPNotFound()
|
||||||
|
except OSError as e:
|
||||||
|
raise aiohttp.web.HTTPConflict(text=str(e))
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ def main():
|
|||||||
|
|
||||||
Project.clean_project_directory()
|
Project.clean_project_directory()
|
||||||
|
|
||||||
executor = concurrent.futures.ThreadPoolExecutor(max_workers=100) # We allow 100 parallel executors
|
executor = concurrent.futures.ThreadPoolExecutor(max_workers=100) # We allow 100 parallel executors
|
||||||
loop = asyncio.get_event_loop().set_default_executor(executor)
|
loop = asyncio.get_event_loop().set_default_executor(executor)
|
||||||
|
|
||||||
CrashReport.instance()
|
CrashReport.instance()
|
||||||
|
Loading…
Reference in New Issue
Block a user