1
0
Fork 0
archivebox/tests/mock_server/server.py

54 lines
1.8 KiB
Python
Raw Normal View History

from os.path import abspath
from os import getcwd
from pathlib import Path
2020-09-24 09:37:27 -04:00
from bottle import route, run, static_file, response, redirect
@route("/")
def index():
return "Hello"
@route("/static/<filename>")
def static_path(filename):
2020-09-23 11:34:05 -04:00
template_path = abspath(getcwd()) / Path("tests/mock_server/templates")
response = static_file(filename, root=template_path)
return response
@route("/static_no_content_type/<filename>")
def static_no_content_type(filename):
template_path = abspath(getcwd()) / Path("tests/mock_server/templates")
response = static_file(filename, root=template_path)
response.set_header("Content-Type", "")
return response
2020-09-14 17:35:45 -04:00
@route("/static/headers/<filename>")
def static_path_with_headers(filename):
template_path = abspath(getcwd()) / Path("tests/mock_server/templates")
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-24 09:37:27 -04:00
@route("/static/400/<filename>", method="HEAD")
def static_400(filename):
template_path = abspath(getcwd()) / Path("tests/mock_server/templates")
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):
template_path = abspath(getcwd()) / Path("tests/mock_server/templates")
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")
def start():
run(host='localhost', port=8080)