mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add acl link header writer
This writer will add a link to the corresponding acl file for all LDP requests.
This commit is contained in:
@@ -23,6 +23,7 @@ export * from './init/RootContainerInitializer';
|
||||
export * from './init/ServerInitializer';
|
||||
|
||||
// LDP/HTTP/Metadata
|
||||
export * from './ldp/http/metadata/AclLinkMetadataWriter';
|
||||
export * from './ldp/http/metadata/BasicMetadataExtractor';
|
||||
export * from './ldp/http/metadata/ConstantMetadataWriter';
|
||||
export * from './ldp/http/metadata/ContentTypeParser';
|
||||
|
||||
25
src/ldp/http/metadata/AclLinkMetadataWriter.ts
Normal file
25
src/ldp/http/metadata/AclLinkMetadataWriter.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { AclManager } from '../../../authorization/AclManager';
|
||||
import type { HttpResponse } from '../../../server/HttpResponse';
|
||||
import { addHeader } from '../../../util/HeaderUtil';
|
||||
import type { RepresentationMetadata } from '../../representation/RepresentationMetadata';
|
||||
import { MetadataWriter } from './MetadataWriter';
|
||||
|
||||
/**
|
||||
* A MetadataWriter that always adds a rel="acl" link header to a response.
|
||||
* The `rel` parameter can be used if a different `rel` value is needed (such as http://www.w3.org/ns/solid/terms#acl).
|
||||
*/
|
||||
export class AclLinkMetadataWriter extends MetadataWriter {
|
||||
private readonly aclManager: AclManager;
|
||||
private readonly rel: string;
|
||||
|
||||
public constructor(aclManager: AclManager, rel = 'acl') {
|
||||
super();
|
||||
this.aclManager = aclManager;
|
||||
this.rel = rel;
|
||||
}
|
||||
|
||||
public async handle(input: { response: HttpResponse; metadata: RepresentationMetadata }): Promise<void> {
|
||||
const identifier = await this.aclManager.getAclDocument({ path: input.metadata.identifier.value });
|
||||
addHeader(input.response, 'Link', `<${identifier.path}>; rel="${this.rel}"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user