#2457·sanic

Invalid request.url when full URI is used as SERVER_NAME

Author: PromyLOPhCreated May 17, 2022Updated May 23, 2026
Labelsbugneeds investigation

Describe the bug When using a full URL as config.SERVER_NAME the request’s URL (request.url) is invalid, as it contains two colons. The code does not properly split the SERVER_NAME, keeping the colon. Splitting on "://" instead works for me, but the code remains very fragile.

Code snippet

python
from sanic import Sanic
from sanic.response import text

app = Sanic("MyHelloWorldApp")
app.config.SERVER_NAME = 'https://www.example.com/api'

@app.get("/foo")
async def foo_handler(request):
        return text(f'{request.url}')
bash
$ curl localhost:8001/foo
https:://www.example.com/foo

Expected behavior The URL should be valid.

bash
$ curl localhost:8001/foo
https://www.example.com/foo

Environment (please complete the following information):

  • OS: Linux-5.4.0-110-generic-x86_64-with-glibc2.33
  • Version Sanic v21.12.1