Skip to content

Invalid request.url when full URI is used as SERVER_NAME  #2457

@PromyLOPh

Description

@PromyLOPh

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

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}')
$ curl localhost:8001/foo
https:://www.example.com/foo

Expected behavior
The URL should be valid.

$ 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions