def test_vhosts():
app = Sanic('test_vhosts')
@app.route('/', host="example.com")
async def handler(request):
return text("You're at example.com!")
@app.route('/', host="subdomain.example.com")
async def handler(request):
return text("You're at subdomain.example.com!")
headers = {"Host": "example.com"}
request, response = app.test_client.get('/', headers=headers)
assert response.text == "You're at example.com!"
headers = {"Host": "subdomain.example.com"}
request, response = app.test_client.get('/', headers=headers)
assert response.text == "You're at subdomain.example.com!"
评论列表
文章目录