test_vhosts.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:sanic 作者: channelcat 项目源码 文件源码
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!"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号