You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ERROR: Undefined index: host on line 214 in file [...]/vendor/tuupola/cors-middleware/src/CorsMiddleware.php.
Fix
Change the setting 'origin.server' => 'localhost' to 'origin.server' => 'http://localhost', i.e. make sure to add the protocol.
Behind the Scenes
In /tuupola/cors-middleware/src/CorsMiddleware.php the function determineServerOrigin() calls $url_chunks = parse_url($this->options["origin.server"]);. According to this comment on php.net:
parse_url() DOES NOT parse correctly URLs without scheme or '//'. For example 'www.xyz.com' is considered as a path, not a host.
I was using 'origin.server' => 'localhost'. Then, parse_url() returns an associative array with path as the only key. The function determineServerOrigin() also adds port. But the final returned object $url will not have a host key.
The function buildSettings() in the same file on line 214 expects the object $serverOrigin (which is the return value of determineServerOrigin() and hence the same object described previously) to have a key host.
Hence my setting of declaring the origin.server without protocol breaks the function buildSettings().
Suggested Fix
Merge the default given in determineServerOrigin() into the result given by the rest of the function to ensure the existence of the three keys scheme, host, port.
Alternatively, enforce the origin.server setting to be specified with protocol.
The text was updated successfully, but these errors were encountered:
Observed
I got the following error:
Fix
Change the setting
'origin.server' => 'localhost'
to'origin.server' => 'http://localhost'
, i.e. make sure to add the protocol.Behind the Scenes
In
/tuupola/cors-middleware/src/CorsMiddleware.php
the functiondetermineServerOrigin()
calls$url_chunks = parse_url($this->options["origin.server"]);
. According to this comment on php.net:I was using
'origin.server' => 'localhost'
. Then,parse_url()
returns an associative array withpath
as the only key. The functiondetermineServerOrigin()
also addsport
. But the final returned object$url
will not have ahost
key.The function
buildSettings()
in the same file on line 214 expects the object$serverOrigin
(which is the return value ofdetermineServerOrigin()
and hence the same object described previously) to have a keyhost
.Hence my setting of declaring the
origin.server
without protocol breaks the functionbuildSettings()
.Suggested Fix
Merge the default given in
determineServerOrigin()
into the result given by the rest of the function to ensure the existence of the three keysscheme
,host
,port
.Alternatively, enforce the
origin.server
setting to be specified with protocol.The text was updated successfully, but these errors were encountered: