Skip to content
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

origin.server Setting Must be Specified with Protocol #86

Open
michaelheider opened this issue Aug 26, 2023 · 0 comments
Open

origin.server Setting Must be Specified with Protocol #86

michaelheider opened this issue Aug 26, 2023 · 0 comments
Assignees

Comments

@michaelheider
Copy link

Observed

I got the following error:

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.

@tuupola tuupola self-assigned this Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants