2020-07-14 02:39:43 +12:00
|
|
|
from os import getcwd
|
|
|
|
from pathlib import Path
|
2020-07-08 07:46:45 +12:00
|
|
|
|
2020-09-25 01:37:27 +12:00
|
|
|
from bottle import route, run, static_file, response, redirect
|
2020-07-14 02:39:43 +12:00
|
|
|
|
|
|
|
@route("/")
|
2020-07-08 07:46:45 +12:00
|
|
|
def index():
|
|
|
|
return "Hello"
|
|
|
|
|
2020-07-14 02:39:43 +12:00
|
|
|
@route("/static/<filename>")
|
|
|
|
def static_path(filename):
|
2020-10-01 08:05:39 +13:00
|
|
|
template_path = Path.cwd().resolve() / "tests/mock_server/templates"
|
2020-09-24 03:34:05 +12:00
|
|
|
response = static_file(filename, root=template_path)
|
|
|
|
return response
|
|
|
|
|
|
|
|
@route("/static_no_content_type/<filename>")
|
|
|
|
def static_no_content_type(filename):
|
2020-10-01 08:05:39 +13:00
|
|
|
template_path = Path.cwd().resolve() / "tests/mock_server/templates"
|
2020-07-23 03:24:08 +12:00
|
|
|
response = static_file(filename, root=template_path)
|
|
|
|
response.set_header("Content-Type", "")
|
|
|
|
return response
|
2020-07-14 02:39:43 +12:00
|
|
|
|
2020-09-15 09:35:45 +12:00
|
|
|
@route("/static/headers/<filename>")
|
|
|
|
def static_path_with_headers(filename):
|
2020-10-01 08:05:39 +13:00
|
|
|
template_path = Path.cwd().resolve() / "tests/mock_server/templates"
|
2020-09-15 09:35:45 +12:00
|
|
|
response = static_file(filename, root=template_path)
|
|
|
|
response.add_header("Content-Language", "en")
|
|
|
|
response.add_header("Content-Script-Type", "text/javascript")
|
|
|
|
response.add_header("Content-Style-Type", "text/css")
|
|
|
|
return response
|
|
|
|
|
2020-09-25 01:37:27 +12:00
|
|
|
@route("/static/400/<filename>", method="HEAD")
|
|
|
|
def static_400(filename):
|
2020-10-01 08:05:39 +13:00
|
|
|
template_path = Path.cwd().resolve() / "tests/mock_server/templates"
|
2020-09-25 01:37:27 +12:00
|
|
|
response = static_file(filename, root=template_path)
|
|
|
|
response.status = 400
|
|
|
|
response.add_header("Status-Code", "400")
|
|
|
|
return response
|
|
|
|
|
|
|
|
@route("/static/400/<filename>", method="GET")
|
|
|
|
def static_200(filename):
|
2020-10-01 08:05:39 +13:00
|
|
|
template_path = Path.cwd().resolve() / "tests/mock_server/templates"
|
2020-09-25 01:37:27 +12:00
|
|
|
response = static_file(filename, root=template_path)
|
|
|
|
response.add_header("Status-Code", "200")
|
|
|
|
return response
|
|
|
|
|
|
|
|
@route("/redirect/headers/<filename>")
|
|
|
|
def redirect_to_static(filename):
|
|
|
|
redirect(f"/static/headers/$filename")
|
|
|
|
|
|
|
|
|
2020-07-08 07:46:45 +12:00
|
|
|
def start():
|
2024-03-02 09:43:53 +13:00
|
|
|
run(host='localhost', port=8080, quiet=True)
|