-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid request.url when full URI is used as SERVER_NAME #2457
Comments
https://www.example.com/api is not a valid server name, it is a complete URI. With that being said, '/' is an invalid character for a hostname, and this should be throwing an error. It should also be documented that SERVER_NAME should be RFC1123 compliant when used. We will look at including an appropriate fix that errors out when using invalid characters and document this appropriately. |
Was something changed? I recall myself implementing support for full URL SERVER_NAME a few years back, although IIRC it wouldn't (yet) support path but at least you could say https to provide correct scheme on external URLs instead of http as used when running behind Nginx. |
@Tronic It hasn't changed, but the internal documentation refers to it being used when host_name isn't present, which in itself is probably wrong. In reality there probably needs to be an "external_url" config item that passes a full path when needed. In reality, it's not well documented, and since everyone can interpret server_name differently, it probably should be documented specifically. It's also concerning because the colon issue may be problematic if using an IPv6 address which probably needs investigation as well. ref: https://sanic.readthedocs.io/en/stable/sanic/api/app.html -> url_for section |
As a bit of background: I am trying to host a sanic application behind a nginx reverse proxy mounted on a non-root path. Unfortunately the documentation provides no information on how to do this and standard ASGI with a |
This is indeed a bug. app = Sanic(__name__)
app.config.SERVER_NAME = "http://www.myserver.com/nested"
@app.get("/handler")
async def handler(request: Request):
return json(
{
"url": request.url,
"scheme": request.scheme,
"host": request.host,
"path": request.path,
}
)
@PromyLOPh would you be willing to submit a PR for us? Should be a small fix to parsing of the Line 715 in 5d683c6
|
Sure, I can prepare a PR. |
Upstream issue at sanic-org/sanic#2457
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 theSERVER_NAME
, keeping the colon. Splitting on"://"
instead works for me, but the code remains very fragile.Code snippet
Expected behavior
The URL should be valid.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: