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');
|
metadata.remove('grpc-status');
|
||||||
}
|
}
|
||||||
if (typeof metadataMap['grpc-message'] === 'string') {
|
if (typeof metadataMap['grpc-message'] === 'string') {
|
||||||
details = decodeURIComponent(metadataMap['grpc-message'] as string);
|
details = decodeURI(metadataMap['grpc-message'] as string);
|
||||||
metadata.remove('grpc-message');
|
metadata.remove('grpc-message');
|
||||||
}
|
}
|
||||||
return { code, details, metadata };
|
return { code, details, metadata };
|
||||||
|
|
|
@ -36,6 +36,10 @@ function isBinaryKey(key: string): boolean {
|
||||||
return key.endsWith('-bin');
|
return key.endsWith('-bin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isCustomMetadata(key: string): boolean {
|
||||||
|
return !key.startsWith('grpc-');
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeKey(key: string): string {
|
function normalizeKey(key: string): string {
|
||||||
return key.toLowerCase();
|
return key.toLowerCase();
|
||||||
}
|
}
|
||||||
|
@ -260,9 +264,13 @@ export class Metadata {
|
||||||
result.add(key, Buffer.from(value, 'base64'));
|
result.add(key, Buffer.from(value, 'base64'));
|
||||||
});
|
});
|
||||||
} else if (values !== undefined) {
|
} else if (values !== undefined) {
|
||||||
values.split(',').forEach(v => {
|
if (isCustomMetadata(key)) {
|
||||||
result.add(key, Buffer.from(v.trim(), 'base64'));
|
values.split(',').forEach(v => {
|
||||||
});
|
result.add(key, Buffer.from(v.trim(), 'base64'));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result.add(key, Buffer.from(values, 'base64'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Array.isArray(values)) {
|
if (Array.isArray(values)) {
|
||||||
|
@ -270,7 +278,11 @@ export class Metadata {
|
||||||
result.add(key, value);
|
result.add(key, value);
|
||||||
});
|
});
|
||||||
} else if (values !== undefined) {
|
} 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) {
|
} catch (error) {
|
||||||
|
|
|
@ -484,9 +484,7 @@ export class Http2ServerCallStream<
|
||||||
const trailersToSend = Object.assign(
|
const trailersToSend = Object.assign(
|
||||||
{
|
{
|
||||||
[GRPC_STATUS_HEADER]: statusObj.code,
|
[GRPC_STATUS_HEADER]: statusObj.code,
|
||||||
[GRPC_MESSAGE_HEADER]: encodeURIComponent(
|
[GRPC_MESSAGE_HEADER]: encodeURI(statusObj.details as string),
|
||||||
statusObj.details as string
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
statusObj.metadata.toHttp2Headers()
|
statusObj.metadata.toHttp2Headers()
|
||||||
);
|
);
|
||||||
|
|
|
@ -553,6 +553,14 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
||||||
done();
|
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