mirror of https://github.com/grpc/grpc-node.git
Only custom-metadata headers should be parsed as comma-separated
This commit is contained in:
parent
dd414b6ddc
commit
2dce08dc99
|
@ -38,7 +38,7 @@ export class MetadataStatusFilter extends BaseFilter implements Filter {
|
|||
metadata.remove('grpc-status');
|
||||
}
|
||||
if (typeof metadataMap['grpc-message'] === 'string') {
|
||||
details = decodeURIComponent(metadataMap['grpc-message'] as string);
|
||||
details = decodeURI(metadataMap['grpc-message'] as string);
|
||||
metadata.remove('grpc-message');
|
||||
}
|
||||
return { code, details, metadata };
|
||||
|
|
|
@ -36,6 +36,10 @@ function isBinaryKey(key: string): boolean {
|
|||
return key.endsWith('-bin');
|
||||
}
|
||||
|
||||
function isCustomMetadata(key: string): boolean {
|
||||
return !key.startsWith('grpc-');
|
||||
}
|
||||
|
||||
function normalizeKey(key: string): string {
|
||||
return key.toLowerCase();
|
||||
}
|
||||
|
@ -260,9 +264,13 @@ export class Metadata {
|
|||
result.add(key, Buffer.from(value, 'base64'));
|
||||
});
|
||||
} else if (values !== undefined) {
|
||||
values.split(',').forEach(v => {
|
||||
result.add(key, Buffer.from(v.trim(), 'base64'));
|
||||
});
|
||||
if (isCustomMetadata(key)) {
|
||||
values.split(',').forEach(v => {
|
||||
result.add(key, Buffer.from(v.trim(), 'base64'));
|
||||
});
|
||||
} else {
|
||||
result.add(key, Buffer.from(values, 'base64'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Array.isArray(values)) {
|
||||
|
@ -270,7 +278,11 @@ export class Metadata {
|
|||
result.add(key, value);
|
||||
});
|
||||
} else if (values !== undefined) {
|
||||
values.split(',').forEach(v => result.add(key, v.trim()));
|
||||
if (isCustomMetadata(key)) {
|
||||
values.split(',').forEach(v => result.add(key, v.trim()));
|
||||
} else {
|
||||
result.add(key, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -484,9 +484,7 @@ export class Http2ServerCallStream<
|
|||
const trailersToSend = Object.assign(
|
||||
{
|
||||
[GRPC_STATUS_HEADER]: statusObj.code,
|
||||
[GRPC_MESSAGE_HEADER]: encodeURIComponent(
|
||||
statusObj.details as string
|
||||
),
|
||||
[GRPC_MESSAGE_HEADER]: encodeURI(statusObj.details as string),
|
||||
},
|
||||
statusObj.metadata.toHttp2Headers()
|
||||
);
|
||||
|
|
|
@ -553,6 +553,14 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
|||
done();
|
||||
});
|
||||
});
|
||||
it('for an error message with a comma', function(done) {
|
||||
client.unary({error: true, message: 'a message, with a comma'}, function(err, data) {
|
||||
assert(err);
|
||||
assert.strictEqual(err.code, clientGrpc.status.UNKNOWN);
|
||||
assert.strictEqual(err.details, 'a message, with a comma');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue