fix: Have AsyncHandlers only check what is necessary

This commit is contained in:
Joachim Van Herwegen
2020-10-05 10:56:35 +02:00
parent 10723bb6b8
commit 4d34cdd12f
11 changed files with 45 additions and 55 deletions

View File

@@ -10,16 +10,17 @@ import { TargetExtractor } from './TargetExtractor';
* TODO: input requires more extensive cleaning/parsing based on headers (see #22).
*/
export class BasicTargetExtractor extends TargetExtractor {
public async canHandle(input: HttpRequest): Promise<void> {
public async canHandle(): Promise<void> {
// Can handle all URLs
}
public async handle(input: HttpRequest): Promise<ResourceIdentifier> {
if (!input.url) {
throw new Error('Missing URL.');
}
if (!input.headers.host) {
throw new Error('Missing host.');
}
}
public async handle(input: HttpRequest): Promise<ResourceIdentifier> {
const isHttps = input.connection && (input.connection as TLSSocket).encrypted;
const url = format({
protocol: `http${isHttps ? 's' : ''}`,