mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Support missing type preferences in ChainedConverter
This commit is contained in:
@@ -32,8 +32,12 @@ export class AcceptPreferenceParser extends PreferenceParser {
|
||||
for (const { name, header, parse } of parsers) {
|
||||
const value = headers[header];
|
||||
if (typeof value === 'string') {
|
||||
preferences[name] = Object.fromEntries(parse(value)
|
||||
const result = Object.fromEntries(parse(value)
|
||||
.map(({ range, weight }): [string, number] => [ range, weight ]));
|
||||
// Interpret empty headers (or headers with no valid values) the same as missing headers
|
||||
if (Object.keys(result).length > 0) {
|
||||
preferences[name] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return preferences;
|
||||
|
||||
@@ -174,15 +174,11 @@ export class ChainedConverter extends RepresentationConverter {
|
||||
if (!type) {
|
||||
throw new BadRequestHttpError('Missing Content-Type header.');
|
||||
}
|
||||
let preferences = input.preferences.type;
|
||||
if (!preferences) {
|
||||
throw new BadRequestHttpError('Missing type preferences.');
|
||||
}
|
||||
preferences = cleanPreferences(preferences);
|
||||
const preferences = cleanPreferences(input.preferences.type);
|
||||
|
||||
const weight = getTypeWeight(type, preferences);
|
||||
if (weight > 0) {
|
||||
this.logger.debug(`No conversion required: ${type} already matches ${Object.keys(input.preferences.type!)}`);
|
||||
this.logger.debug(`No conversion required: ${type} already matches ${Object.keys(preferences)}`);
|
||||
return { value: type, weight };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user