-
-
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
Fix request.url with full URI as SERVER_NAME #2458
base: 21.12LTS
Are you sure you want to change the base?
Conversation
What if the SERVER_NAME is: |
My understanding was that you’d not prepend |
That might not be the case, especially if you wanted to build URLs that had Consider your code:
versus w/
As you suggested, with Looking into this further, it looks like we also need to handle |
So what is I don’t have time to propose a fix for |
No worries. It really should only be the domain, but that doesn't mean because of historical reasons we shouldn't be supporting the scheme too. |
The property documentation does say it uses "`config.SERVER_NAME` if in full URL format", which -according to the URI spec- requires a scheme to be defined. URIs starting with Therefore, I personally agree with @PromyLOPh here in believing that splitting on |
If that is the the decision we need to do some validation. As it stands there is certainly a use when you would need an empty scheme and we are not providing that. To be honest, I'm leaning more towards closing this PR because there is a deeper underlying issue that needs to be fixed and made consistent through the application and not just a band-aid in one location. |
@ahopkins Do you mean for https vs. wss? Other than that I cannot really think of reasons to leave the scheme open. In particular, nothing should have external URLs without TLS anymore. This really needs a consistent fix (with support for nested external path) but frankly it has been a couple of years with no-one willing to do the fixing. My personal take is to cater to practical use cases rather than trying to read exactly RFCs say on URL parsing, and my practical cases would include hosting behind nginx proxy (meaning that scheme, hostname, port and path are different than internally, but Sanic should be able to produce wss for websocket URLs, even when Sanic connection is over plain http, with SERVER_NAME defined as https). |
Yup. Consistency is the pain point here. I am hesitant to add yet another minor fix, and will try and take a crack in the coming weeks at revamping this. It will likely cause some breaking changes. All the more reason to get it into this June release and not wait. |
5cfa763
to
d41c478
Compare
I updated my code to use |
EDIT: Ignore me; you meant leaving the scheme off, not leaving it blank. |
@ahopkins This seems simple and approved? Can we make it ready and rerun the CI? I think the main branch would also need it. |
I do not remember approving this, because I am not in agreement with this strategy yet. I actually was thinking about this one yesterday while in the car. There is an absolute mess of inconsistent uses here and the whole API regarding naming, URL generation, domain setting, etc needs to be overhauled. I was going to propose a solution this week that would:
What else am I missing? |
I am not familiar with the URL APIs in Sanic but this sounds like This PR seems like simple fix to an issue related to the feature that using |
I don't think it is a simple fix since it will be a breaking change. |
Just a brief comment now that my intuition says that all four of these are ideas to be avoided (just intuition, no reasoning yet). Certainly needs more thought and consideration. Would rather see some breaking evolution of existing facilities, e.g. via this PR, as the lesser evil than completely breaking it with a new/parallel system. |
I am super reluctant to cause these breaking changes. The code that implements Unfortunately we are stuck with a legacy API from 2017. I do not blame the original author or developers since the use case for building URLs with If we try to "fix" the issue by changing how I am open to suggestions on ways to implement this if anyone has another idea that will:
|
Possible approaches to start with:
Adding any parallel settings or url functions still doesn't seem any better than it was when I wrote about my intuition first. I am afraid that some degree of breaking cannot be avoided with this. |
Should fix #2457. Not sure why
.strip(':')
was suggested – we can just split at the correct token, though I’m leaving other places where this kind of splitting occurs untouched. I’m also keeping two currently failing tests commented out, because they are out of scope for this fix and probably require larger refactoring.