mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Undo authorization on OPTIONS requests
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { ResponseDescription } from './ResponseDescription';
|
||||
|
||||
/**
|
||||
* Corresponds to a 204 response.
|
||||
*/
|
||||
export class NoContentResponseDescription extends ResponseDescription {
|
||||
public constructor() {
|
||||
super(204);
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user