fix: Improve headers handling

This commit is contained in:
Cristian 2020-09-24 08:37:27 -05:00 committed by Cristian Vargas
parent a40af98ced
commit 62ed11a5ca
6 changed files with 60 additions and 3 deletions

View file

@ -2,7 +2,7 @@ from os.path import abspath
from os import getcwd
from pathlib import Path
from bottle import route, run, static_file, response
from bottle import route, run, static_file, response, redirect
@route("/")
def index():
@ -30,5 +30,25 @@ def static_path_with_headers(filename):
response.add_header("Content-Style-Type", "text/css")
return response
@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)