Skip to content

Commit

Permalink
fix: Correctly parse URL domain
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Oct 16, 2020
1 parent 4df2645 commit 5fa0686
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/ldp/http/BasicTargetExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { TLSSocket } from 'tls';
import { format } from 'url';
import type { HttpRequest } from '../../server/HttpRequest';
import { toCanonicalUriPath } from '../../util/Util';
import type { ResourceIdentifier } from '../representation/ResourceIdentifier';
Expand All @@ -23,11 +22,11 @@ export class BasicTargetExtractor extends TargetExtractor {
throw new Error('Missing host.');
}
const isHttps = input.connection && (input.connection as TLSSocket).encrypted;
const path = format({
protocol: `http${isHttps ? 's' : ''}`,
host: toCanonicalUriPath(input.headers.host),
pathname: toCanonicalUriPath(input.url),
});

// URL object applies punycode encoding to domain
const base = `http${isHttps ? 's' : ''}://${input.headers.host}`;
const url = toCanonicalUriPath(input.url);
const path = new URL(url, base).href;

return { path };
}
Expand Down

0 comments on commit 5fa0686

Please sign in to comment.