2020-08-27 10:07:46 +03:00
|
|
|
# coding=utf-8
|
2022-02-05 08:56:33 +03:00
|
|
|
from flask import request, make_response
|
2022-02-14 11:13:33 +03:00
|
|
|
from app import app
|
2020-08-27 10:07:46 +03:00
|
|
|
|
2022-02-05 08:56:33 +03:00
|
|
|
|
2020-08-27 10:07:46 +03:00
|
|
|
@app.route("/default-headers")
|
|
|
|
def default_headers():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert (
|
|
|
|
"hurl" in request.headers["User-Agent"]
|
|
|
|
or "curl" in request.headers["User-Agent"]
|
|
|
|
)
|
|
|
|
assert request.headers["Host"] == "localhost:8000"
|
|
|
|
assert "Content-Length" not in request.headers
|
|
|
|
return ""
|
2020-08-27 10:07:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/custom-headers")
|
|
|
|
def custom_headers():
|
|
|
|
# TODO: what is expected when request header has multiple values ?
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Fruit"] == "Raspberry,Apple,Banana,Grape"
|
|
|
|
assert request.headers["Color"] == "Green"
|
|
|
|
return ""
|
2020-08-27 10:07:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/custom-headers-utf8")
|
|
|
|
def custom_headers_utf8():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert len(request.headers["Beverage"]) == 5
|
|
|
|
assert request.headers["Beverage"] == "\x63\x61\x66\xc3\xa9"
|
|
|
|
return ""
|
|
|
|
|
2020-08-27 10:07:46 +03:00
|
|
|
|
2021-09-10 09:37:15 +03:00
|
|
|
@app.route("/custom-headers-value")
|
|
|
|
def custom_headers_value():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Id"] == "#123"
|
|
|
|
return ""
|
|
|
|
|
2020-08-27 10:07:46 +03:00
|
|
|
|
2021-05-14 20:31:18 +03:00
|
|
|
@app.route("/custom-headers-quote")
|
|
|
|
def custom_headers_quotes():
|
2022-02-05 08:56:33 +03:00
|
|
|
assert request.headers["Header1"] == "'"
|
|
|
|
return ""
|
2021-05-14 20:31:18 +03:00
|
|
|
|
|
|
|
|
2020-08-27 10:07:46 +03:00
|
|
|
@app.route("/response-headers")
|
|
|
|
def response_headers():
|
|
|
|
resp = make_response()
|
2022-02-05 08:56:33 +03:00
|
|
|
# resp.headers['Beverage'] = '\x63\x61\x66\xc3\xa9'
|
|
|
|
resp.headers["Beverage"] = "cafe"
|
|
|
|
return resp
|