mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Let Representations always have a body
This is relevant when the request has a content-type but no data.
This commit is contained in:
@@ -24,6 +24,11 @@ export class BasicRepresentation implements Representation {
|
||||
public readonly metadata: RepresentationMetadata;
|
||||
public readonly binary: boolean;
|
||||
|
||||
/**
|
||||
* An empty Representation
|
||||
*/
|
||||
public constructor();
|
||||
|
||||
/**
|
||||
* @param data - The representation data
|
||||
* @param metadata - The representation metadata
|
||||
@@ -86,13 +91,15 @@ export class BasicRepresentation implements Representation {
|
||||
);
|
||||
|
||||
public constructor(
|
||||
data: Readable | any[] | string,
|
||||
metadata: RepresentationMetadata | MetadataRecord | MetadataIdentifier | string,
|
||||
data?: Readable | any[] | string,
|
||||
metadata?: RepresentationMetadata | MetadataRecord | MetadataIdentifier | string,
|
||||
metadataRest?: MetadataRecord | string | boolean,
|
||||
binary?: boolean,
|
||||
) {
|
||||
if (typeof data === 'string' || Array.isArray(data)) {
|
||||
data = guardedStreamFrom(data);
|
||||
} else if (!data) {
|
||||
data = guardedStreamFrom([]);
|
||||
}
|
||||
this.data = guardStream(data);
|
||||
|
||||
@@ -110,4 +117,11 @@ export class BasicRepresentation implements Representation {
|
||||
}
|
||||
this.binary = binary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data should only be interpreted if there is a content type.
|
||||
*/
|
||||
public get isEmpty(): boolean {
|
||||
return !this.metadata.contentType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,4 +19,10 @@ export interface Representation {
|
||||
* (as opposed to complex objects).
|
||||
*/
|
||||
binary: boolean;
|
||||
/**
|
||||
* Whether the data stream is empty.
|
||||
* This being true does not imply that the data stream has a length of more than 0,
|
||||
* only that it is a possibility and should be read to be sure.
|
||||
*/
|
||||
isEmpty: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user