fix: Take host into account when extracting identifier

This commit is contained in:
Joachim Van Herwegen
2020-07-10 14:17:10 +02:00
parent 792323797d
commit cff9790b6e
4 changed files with 34 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
import { format } from 'url';
import { HttpRequest } from '../../server/HttpRequest';
import { ResourceIdentifier } from '../representation/ResourceIdentifier';
import { TargetExtractor } from './TargetExtractor';
import { TLSSocket } from 'tls';
/**
* Extracts an identifier from an incoming {@link HttpRequest}.
@@ -14,6 +16,13 @@ export class SimpleTargetExtractor extends TargetExtractor {
}
public async handle(input: HttpRequest): Promise<ResourceIdentifier> {
return { path: input.url };
const isHttps = input.connection && (input.connection as TLSSocket).encrypted;
const url = format({
protocol: `http${isHttps ? 's' : ''}`,
host: input.headers.host,
pathname: input.url,
});
return { path: url };
}
}