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

Derive the port from the protocol in cases where it's not explicitly in the URL #83583

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,32 @@ export class HeadlessChromiumDriver {
private _shouldUseCustomHeaders(conditions: ConditionalHeadersConditions, url: string) {
const { hostname, protocol, port, pathname } = parseUrl(url);

if (port === null) throw new Error(`URL missing port: ${url}`);
// `port` is null in URLs that don't explicitly state it,
// however we can derive the port from the protocol (http/https)
// IE: https://feeds-staging.elastic.co/kibana/v8.0.0.json
const derivedPort = (() => {
if (port) {
return port;
}

if (protocol === 'http:') {
return '80';
}

if (protocol === 'https:') {
return '443';
}

return null;
})();

if (derivedPort === null) throw new Error(`URL missing port: ${url}`);
if (pathname === null) throw new Error(`URL missing pathname: ${url}`);

return (
hostname === conditions.hostname &&
protocol === `${conditions.protocol}:` &&
this._shouldUseCustomHeadersForPort(conditions, port) &&
this._shouldUseCustomHeadersForPort(conditions, derivedPort) &&
pathname.startsWith(`${conditions.basePath}/`)
);
}
Expand Down