-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Implement Application.add_subdomain (#1342) #2194
Conversation
It's not exactly what is explained in #1342 but I think it's what was intended. Mind the fact, that I don't think this can be merged given the checklist is not complete and that IMO the user experience is not good enough. With the current code, the domain is hardcoded which, I think, will be a pain during dev because the dev has to override DNS resolution in her WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparent from comments I think this is looking good. Would be great if if could be included in the next release?
if subapp.frozen: | ||
raise RuntimeError("Cannot add frozen application") | ||
if subdomain == '': | ||
raise ValueError("Subdomain cannot be empty") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do any more validation of the subdomain? Eg. that it doesn't contain spaces or /
, does yarl or urllib allow this?
resource.add_prefix(prefix) | ||
|
||
def url_for(self, *args, **kwargs): | ||
raise RuntimeError(".url_for() is not supported " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe NotImplementedError
would make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
|
||
@asyncio.coroutine | ||
def resolve(self, request): | ||
if not request.headers['Host'] == self._subdomain: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if Host
is missing from headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will fail. Should I do something specific here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely just .get()
would work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess overall is looking very good, I just made a few comments on the possibility to replace subdomain with domain inline with code
@@ -197,6 +197,23 @@ def add_subapp(self, prefix, subapp): | |||
subapp._set_loop(self._loop) | |||
return resource | |||
|
|||
def add_subdomain(self, subdomain, subapp): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to add_domain(self, domain, subapp)? The way you did it actually enables multi-site apps on different domains, not only subdomains I think, so why don't just change the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
|
||
def __init__(self, subdomain, app): | ||
super().__init__() | ||
self._subdomain = subdomain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go for changing subdomain to domain, I guess it might be useful to use Yarl to parse the subdomain here so we get for free the port number and can actually dispatch on the actual host (domain + port number)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that we should patch yarl to parse the domain wiht subdomain?
|
||
@asyncio.coroutine | ||
def resolve(self, request): | ||
if not request.headers['Host'] == self._subdomain: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, pending the decision to have domain in place of subdomain, I guess using Yarl to parse the Host header here is also safer.
I think #2809 is better and more general |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
What do these changes do?
Implement basic subdomain support
Are there changes in behavior for the user?
Yes, one can add a subapp for a given domain as follow:
Related issue number
#1342
Checklist
CONTRIBUTORS.txt
changes
folder<issue_id>.<type>
for example (588.bug)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.