Complete worked example
python
from flask import Flask
def host_status(host):
app = Flask(__name__)
app.config.update(TESTING=True, TRUSTED_HOSTS=['trusted.test'])
@app.get('/health')
def health():
return {'ok': True}
return app.test_client().get('/health', headers={'Host': host}).status_code- Reasoning
- The fixture permits trusted.test and sends a real client request with a controlled Host header. The framework returns 400 for an untrusted host before a normal successful response is accepted.