Uh oh!
There was an error while loading. Please reload this page.
feat: improve multiple domain support - #6759
Conversation
| protected function detectURI(string $protocol, string $baseURL) | ||
| { | ||
| // Passing the config is unnecessary but left for legacy purposes | ||
| // @TODO For what? Why clone? |
There was a problem hiding this comment.
The clone prevents URI testing from changing the App Config globally.
There was a problem hiding this comment.
The reason for clone is only for testing, I would like to remove it.
--- a/system/HTTP/IncomingRequest.php+++ b/system/HTTP/IncomingRequest.php@@ -195,12 +195,7 @@ class IncomingRequest extends Request
*/
protected function detectURI(string $protocol, string $baseURL)
{
- // Passing the config is unnecessary but left for legacy purposes- // @TODO For what? Why clone?- $config = clone $this->config;- $config->baseURL = $baseURL;-- $this->setPath($this->detectPath($protocol), $config);+ $this->setPath($this->detectPath($this->config->uriProtocol), $this->config);
}
/**There was a problem hiding this comment.
And deprecate the baseURL input? Is that really only for testing?
There was a problem hiding this comment.
Both $protocol and $baseURL of detectURI() are not needed.
__construct():
CodeIgniter4/system/HTTP/IncomingRequest.php
Line 172 in 11680d6
CodeIgniter4/system/HTTP/IncomingRequest.php
Lines 198 to 205 in 11680d6
michalsn
left a comment
There was a problem hiding this comment.
This may be very useful feature.
At some point we probably should consider providing some easy function (helper) to generate a URL to a different host than this defined in baseURL.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
b984b8f to
52a8589CompareThe URI object is updated in IncomingRequest constructor.
52a8589 to
b6e0976Comparekenjis
commented
Oct 27, 2022
Is this a breaking change? |
MGatner
left a comment
There was a problem hiding this comment.
I think this is mostly okay. I want to hear more about the write-back to App Config - that seems like a pretty big possibility for issues to creep in, and ones that would be difficult to trace. As far as I can tell the logic here is all self-contained, and since current_url() uses this class we shouldn't need to touch the Config.
| if ($config->baseURL === '') { | ||
| // @codeCoverageIgnoreStart | ||
| exit('You have an empty or invalid base URL. The baseURL value must be set in Config\App.php, or through the .env file.'); |
There was a problem hiding this comment.
This used to be conditional on !is_cli() - what is the justification or precedent for requiring CLI to have this set?
| // Update Config\App::$baseURL | ||
| $uri = new URI($baseURL); | ||
| $uri->setHost($host); | ||
| $this->config->baseURL = $uri; |
There was a problem hiding this comment.
I really don't like components updating global Config values. This seems like a bad idea. What does this fix?
There was a problem hiding this comment.
Without this, all helpers will return "old" URLs, not one of those defined in allowedHostnames. That's basically the whole point of all these changes.
I have an app where subdomains and custom domains are used, but I use a more dynamic approach and handle it via Registrars. I would recommend this way, but the only downside is that we can't make it work with one config variable - it's a bit more complicated.
There was a problem hiding this comment.
We need the current real baseURL with allowedHostnames in somewhere.
I think Config\App::$baseURL in shared Config object is best,
because the baseURL is only one in a request and never changes. I don't see any problems.
But if something wrong that I miss, we need to save the current baseURL somewhere else.
Where?
There was a problem hiding this comment.
I would rather see anything that needs to rely on "URL for the incoming request" to use a component that represents that (IncomingRequest, current_url(), etc). It seems very counterintuitive that our Config values are dependent on infrastructure context.
I get that this is the most straightforward approach to a fix, but I think it pokes a new hole in our architecture that is liable to leak, grow bigger, etc.
I'm not a fan of the proliferation of global URL helpers we already have but I would prefer something like current_base_url() to this.
There was a problem hiding this comment.
Re: Registrars... I think that is a great solution at the project level, and would encourage it for individuals who need this currently.
There was a problem hiding this comment.
Indeed, it may seem counter-intuitive that the value of one Config object changes dynamically.
I think it is better that the URI object in IncomingRequest has all the URL related data including the current baseURL.
Uh oh!
There was an error while loading. Please reload this page.
kenjis
commented
Oct 29, 2022
Go to #6785 |
Description
Fixes#5807
Related #6746
Config\App::$allowedHostnamesConfig\App::$baseURLinIncomingRequestifHTTP_HOSTis an allowed hostnameChanges:
current_url(),base_url(),site_url()will return the URL with allowedHTTP_HOSTprevious_url()will return the site URL with allowedHTTP_HOSTwhen cannot get it from session norHTTP_REFERERThe following functions/methods are affected (There may be others):
Ref #4651
Checklist: