fix: Undo authorization on OPTIONS requests

This commit is contained in:
Joachim Van Herwegen
2022-04-04 11:50:00 +02:00
parent 48efc6fae1
commit 97e600bf4f
8 changed files with 9 additions and 101 deletions

View File

@@ -1,36 +0,0 @@
import type { ResourceSet } from '../../storage/ResourceSet';
import { NotFoundHttpError } from '../../util/errors/NotFoundHttpError';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { NoContentResponseDescription } from '../output/response/NoContentResponseDescription';
import type { ResponseDescription } from '../output/response/ResponseDescription';
import type { OperationHandlerInput } from './OperationHandler';
import { OperationHandler } from './OperationHandler';
/**
* Handles OPTIONS {@link Operation}s by always returning a 204.
*/
export class OptionsOperationHandler extends OperationHandler {
private readonly resourceSet: ResourceSet;
/**
* Uses a {@link ResourceSet} to determine the existence of the target resource which impacts the response code.
* @param resourceSet - {@link ResourceSet} that knows if the target resource exists or not.
*/
public constructor(resourceSet: ResourceSet) {
super();
this.resourceSet = resourceSet;
}
public async canHandle({ operation }: OperationHandlerInput): Promise<void> {
if (operation.method !== 'OPTIONS') {
throw new NotImplementedHttpError('This handler only supports OPTIONS operations');
}
}
public async handle({ operation }: OperationHandlerInput): Promise<ResponseDescription> {
if (!await this.resourceSet.hasResource(operation.target)) {
throw new NotFoundHttpError();
}
return new NoContentResponseDescription();
}
}

View File

@@ -1,10 +0,0 @@
import { ResponseDescription } from './ResponseDescription';
/**
* Corresponds to a 204 response.
*/
export class NoContentResponseDescription extends ResponseDescription {
public constructor() {
super(204);
}
}

View File

@@ -83,7 +83,6 @@ export * from './http/ldp/DeleteOperationHandler';
export * from './http/ldp/GetOperationHandler';
export * from './http/ldp/HeadOperationHandler';
export * from './http/ldp/OperationHandler';
export * from './http/ldp/OptionsOperationHandler';
export * from './http/ldp/PatchOperationHandler';
export * from './http/ldp/PostOperationHandler';
export * from './http/ldp/PutOperationHandler';
@@ -106,7 +105,6 @@ export * from './http/output/metadata/WwwAuthMetadataWriter';
// HTTP/Output/Response
export * from './http/output/response/CreatedResponseDescription';
export * from './http/output/response/NoContentResponseDescription';
export * from './http/output/response/OkResponseDescription';
export * from './http/output/response/ResetResponseDescription';
export * from './http/output/response/ResponseDescription';