-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhypercorn_goDASHbed.py
executable file
·53 lines (41 loc) · 1.77 KB
/
hypercorn_goDASHbed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from functools import partial
import trio
from hypercorn.trio import serve
from hypercorn.config import Config
from quart import send_from_directory
from quart_trio import QuartTrio
from os import path
# this defines the root folder containing our DASH dataset
dash_content_path = '/var/www/html/'
# define the config setup for our testbed
config = Config()
config.bind = ["10.0.0.1:443"] # port number to use for HTTPS
config.insecure_bind = ["10.0.0.1:80"] # port number to use for QUIC
# locations for the cert and key
config.certfile = "../godash/godash/http/certs/cert.pem"
config.keyfile = "../godash/godash/http/certs/key.pem"
# this 'root_path' is needed by QuartTrio to point to the DASH video content folder
app = QuartTrio(__name__, root_path=dash_content_path)
# return 404, if file not found
@app.errorhandler(404)
# @app.route('/')
async def page_not_found(error):
return ' File not found', 404
# this return index.html if nothing is added to the url and port
@app.route('/')
async def root():
print("returning index.html",)
return await send_from_directory(dash_content_path, 'index.html'), 200
# this return a file if a path is added after the url and port
@app.route('/<path:path_to_DASH_files>')
async def index(path_to_DASH_files=dash_content_path):
# if the file does not exist, return 404
path_to_file = path.join(dash_content_path, path_to_DASH_files)
if not path.isfile(path_to_file):
print("This file does not exist:", path.isfile(path_to_file))
return path_to_file + ' : File not found', 404
# we need the await or we get coroutine error
print("File downloaded", path_to_file)
return await send_from_directory(dash_content_path, path_to_DASH_files), 200
# use trio to get our files
trio.run(partial(serve, app, config))