mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Store ETag in metadata
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { getETag } from '../../storage/Conditions';
|
||||
import type { ResourceStore } from '../../storage/ResourceStore';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { assertReadConditions } from '../../util/ResourceUtil';
|
||||
import { HH } from '../../util/Vocabularies';
|
||||
import { OkResponseDescription } from '../output/response/OkResponseDescription';
|
||||
import type { ResponseDescription } from '../output/response/ResponseDescription';
|
||||
import type { OperationHandlerInput } from './OperationHandler';
|
||||
@@ -30,6 +32,10 @@ export class GetOperationHandler extends OperationHandler {
|
||||
// Check whether the cached representation is still valid or it is necessary to send a new representation
|
||||
assertReadConditions(body, operation.conditions);
|
||||
|
||||
// Add the ETag of the returned representation
|
||||
const etag = getETag(body.metadata);
|
||||
body.metadata.set(HH.terms.etag, etag);
|
||||
|
||||
return new OkResponseDescription(body.metadata, body.data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { getETag } from '../../storage/Conditions';
|
||||
import type { ResourceStore } from '../../storage/ResourceStore';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { assertReadConditions } from '../../util/ResourceUtil';
|
||||
import { HH } from '../../util/Vocabularies';
|
||||
import { OkResponseDescription } from '../output/response/OkResponseDescription';
|
||||
import type { ResponseDescription } from '../output/response/ResponseDescription';
|
||||
import type { OperationHandlerInput } from './OperationHandler';
|
||||
@@ -34,6 +36,10 @@ export class HeadOperationHandler extends OperationHandler {
|
||||
// Generally it doesn't make much sense to use condition headers with a HEAD request, but it should be supported.
|
||||
assertReadConditions(body, operation.conditions);
|
||||
|
||||
// Add the ETag of the returned representation
|
||||
const etag = getETag(body.metadata);
|
||||
body.metadata.set(HH.terms.etag, etag);
|
||||
|
||||
return new OkResponseDescription(body.metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { HttpResponse } from '../../../server/HttpResponse';
|
||||
import { getETag } from '../../../storage/Conditions';
|
||||
import { addHeader } from '../../../util/HeaderUtil';
|
||||
import { DC } from '../../../util/Vocabularies';
|
||||
import { DC, HH } from '../../../util/Vocabularies';
|
||||
import type { RepresentationMetadata } from '../../representation/RepresentationMetadata';
|
||||
import { MetadataWriter } from './MetadataWriter';
|
||||
|
||||
@@ -15,9 +14,9 @@ export class ModifiedMetadataWriter extends MetadataWriter {
|
||||
const date = new Date(modified.value);
|
||||
addHeader(input.response, 'Last-Modified', date.toUTCString());
|
||||
}
|
||||
const etag = getETag(input.metadata);
|
||||
const etag = input.metadata.get(HH.terms.etag);
|
||||
if (etag) {
|
||||
addHeader(input.response, 'ETag', etag);
|
||||
addHeader(input.response, 'ETag', etag.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user