fix: Ensure the ETag is representation specific

This commit is contained in:
Joachim Van Herwegen
2023-03-30 13:23:04 +02:00
parent 46ceb6d7eb
commit c3f48ddb97
14 changed files with 276 additions and 102 deletions

View File

@@ -1,5 +1,6 @@
import type { ResourceStore } from '../../storage/ResourceStore';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { assertReadConditions } from '../../util/ResourceUtil';
import { OkResponseDescription } from '../output/response/OkResponseDescription';
import type { ResponseDescription } from '../output/response/ResponseDescription';
import type { OperationHandlerInput } from './OperationHandler';
@@ -26,6 +27,9 @@ export class GetOperationHandler extends OperationHandler {
public async handle({ operation }: OperationHandlerInput): Promise<ResponseDescription> {
const body = await this.store.getRepresentation(operation.target, operation.preferences, operation.conditions);
// Check whether the cached representation is still valid or it is necessary to send a new representation
assertReadConditions(body, operation.conditions);
return new OkResponseDescription(body.metadata, body.data);
}
}

View File

@@ -1,5 +1,6 @@
import type { ResourceStore } from '../../storage/ResourceStore';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { assertReadConditions } from '../../util/ResourceUtil';
import { OkResponseDescription } from '../output/response/OkResponseDescription';
import type { ResponseDescription } from '../output/response/ResponseDescription';
import type { OperationHandlerInput } from './OperationHandler';
@@ -29,6 +30,10 @@ export class HeadOperationHandler extends OperationHandler {
// Close the Readable as we will not return it.
body.data.destroy();
// Check whether the cached representation is still valid or it is necessary to send a new representation.
// Generally it doesn't make much sense to use condition headers with a HEAD request, but it should be supported.
assertReadConditions(body, operation.conditions);
return new OkResponseDescription(body.metadata);
}
}