mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add logging
* feat: Add logging * refactor: Configure the logger for the tests once globally * feat: Add logging * fix: Fix ESLint errors due to merge conflicts * Review log and error messages. * refactor: Cleanup a bit * refactor: Change to logger info calls Co-authored-by: Ruben Verborgh <ruben@verborgh.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { TLSSocket } from 'tls';
|
||||
import { getLoggerFor } from '../../logging/LogUtil';
|
||||
import type { HttpRequest } from '../../server/HttpRequest';
|
||||
import { toCanonicalUriPath } from '../../util/Util';
|
||||
import type { ResourceIdentifier } from '../representation/ResourceIdentifier';
|
||||
@@ -10,22 +11,28 @@ import { TargetExtractor } from './TargetExtractor';
|
||||
* TODO: input requires more extensive cleaning/parsing based on headers (see #22).
|
||||
*/
|
||||
export class BasicTargetExtractor extends TargetExtractor {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
public async canHandle(): Promise<void> {
|
||||
// Can handle all URLs
|
||||
}
|
||||
|
||||
public async handle(input: HttpRequest): Promise<ResourceIdentifier> {
|
||||
if (!input.url) {
|
||||
throw new Error('Missing URL.');
|
||||
public async handle(request: HttpRequest): Promise<ResourceIdentifier> {
|
||||
if (!request.url) {
|
||||
this.logger.error('The request has no URL');
|
||||
throw new Error('Missing URL');
|
||||
}
|
||||
if (!input.headers.host) {
|
||||
throw new Error('Missing host.');
|
||||
if (!request.headers.host) {
|
||||
this.logger.error('The request has no Host header');
|
||||
throw new Error('Missing Host header');
|
||||
}
|
||||
const isHttps = input.connection && (input.connection as TLSSocket).encrypted;
|
||||
|
||||
const isHttps = request.connection && (request.connection as TLSSocket).encrypted;
|
||||
this.logger.debug(`Request is using HTTPS: ${isHttps}`);
|
||||
|
||||
// URL object applies punycode encoding to domain
|
||||
const base = `http${isHttps ? 's' : ''}://${input.headers.host}`;
|
||||
const url = toCanonicalUriPath(input.url);
|
||||
const base = `http${isHttps ? 's' : ''}://${request.headers.host}`;
|
||||
const url = toCanonicalUriPath(request.url);
|
||||
const path = new URL(url, base).href;
|
||||
|
||||
return { path };
|
||||
|
||||
Reference in New Issue
Block a user