Implement Application.add_subdomain (#1342)#2194
Implement Application.add_subdomain (#1342)#2194amirouche wants to merge 1 commit intoaio-libs:masterfrom amirouche:web-subdomains-routes
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? |
samuelcolvin
left a comment
There was a problem hiding this comment.
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.
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.
maybe NotImplementedError would make more sense?
|
|
||
| @asyncio.coroutine | ||
| def resolve(self, request): | ||
| if not request.headers['Host'] == self._subdomain: |
There was a problem hiding this comment.
what if Host is missing from headers?
There was a problem hiding this comment.
It will fail. Should I do something specific here?
There was a problem hiding this comment.
Surely just .get() would work?
espositofulvio
left a comment
There was a problem hiding this comment.
I guess overall is looking very good, I just made a few comments on the possibility to replace subdomain with domain inline with code
| subapp._set_loop(self._loop) | ||
| return resource | ||
|
|
||
| def add_subdomain(self, subdomain, subapp): |
There was a problem hiding this comment.
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?
|
|
||
| def __init__(self, subdomain, app): | ||
| super().__init__() | ||
| self._subdomain = subdomain |
There was a problem hiding this comment.
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.
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.
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.txtchangesfolder<issue_id>.<type>for example (588.bug)issue_idchange 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.