mirror of https://github.com/grpc/grpc-node.git
Normalize keys when getting and removing metadata items
This commit is contained in:
parent
d676cc9620
commit
c0735e0b7b
|
@ -102,21 +102,23 @@ Metadata.prototype.add = function(key, value) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the given key and any associated values.
|
* Remove the given key and any associated values. Normalizes the key.
|
||||||
* @param {String} key The key to remove
|
* @param {String} key The key to remove
|
||||||
*/
|
*/
|
||||||
Metadata.prototype.remove = function(key) {
|
Metadata.prototype.remove = function(key) {
|
||||||
|
key = normalizeKey(key);
|
||||||
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
|
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
|
||||||
delete this._internal_repr[key];
|
delete this._internal_repr[key];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of all values associated with the key.
|
* Gets a list of all values associated with the key. Normalizes the key.
|
||||||
* @param {String} key The key to get
|
* @param {String} key The key to get
|
||||||
* @return {Array.<String|Buffer>} The values associated with that key
|
* @return {Array.<String|Buffer>} The values associated with that key
|
||||||
*/
|
*/
|
||||||
Metadata.prototype.get = function(key) {
|
Metadata.prototype.get = function(key) {
|
||||||
|
key = normalizeKey(key);
|
||||||
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
|
if (Object.prototype.hasOwnProperty.call(this._internal_repr, key)) {
|
||||||
return this._internal_repr[key];
|
return this._internal_repr[key];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -135,10 +135,10 @@ describe('Metadata', function() {
|
||||||
metadata.remove('key');
|
metadata.remove('key');
|
||||||
assert.deepEqual(metadata.get('key'), []);
|
assert.deepEqual(metadata.get('key'), []);
|
||||||
});
|
});
|
||||||
it('does not normalize keys', function() {
|
it('Normalizes keys', function() {
|
||||||
metadata.add('key', 'value');
|
metadata.add('key', 'value');
|
||||||
metadata.remove('KEY');
|
metadata.remove('KEY');
|
||||||
assert.deepEqual(metadata.get('key'), ['value']);
|
assert.deepEqual(metadata.get('key'), []);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#get', function() {
|
describe('#get', function() {
|
||||||
|
@ -150,8 +150,8 @@ describe('Metadata', function() {
|
||||||
it('gets all values associated with a key', function() {
|
it('gets all values associated with a key', function() {
|
||||||
assert.deepEqual(metadata.get('key'), ['value1', 'value2']);
|
assert.deepEqual(metadata.get('key'), ['value1', 'value2']);
|
||||||
});
|
});
|
||||||
it('does not normalize keys', function() {
|
it('Normalizes keys', function() {
|
||||||
assert.deepEqual(metadata.get('KEY'), []);
|
assert.deepEqual(metadata.get('KEY'), ['value1', 'value2']);
|
||||||
});
|
});
|
||||||
it('returns an empty list for non-existent keys', function() {
|
it('returns an empty list for non-existent keys', function() {
|
||||||
assert.deepEqual(metadata.get('non-existent-key'), []);
|
assert.deepEqual(metadata.get('non-existent-key'), []);
|
||||||
|
|
Loading…
Reference in New Issue