Fixed handling of binary metadata values

pull/3099/head
murgatroid99 9 years ago
parent e634f9afdf
commit dd7e017e30
  1. 23
      src/node/ext/call.cc
  2. 4
      src/node/src/metadata.js

@ -111,17 +111,19 @@ bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array,
NanAssignPersistent(*handle, value); NanAssignPersistent(*handle, value);
resources->handles.push_back(unique_ptr<PersistentHolder>( resources->handles.push_back(unique_ptr<PersistentHolder>(
new PersistentHolder(handle))); new PersistentHolder(handle)));
continue; } else {
return false;
} }
}
if (value->IsString()) {
Handle<String> string_value = value->ToString();
NanUtf8String *utf8_value = new NanUtf8String(string_value);
resources->strings.push_back(unique_ptr<NanUtf8String>(utf8_value));
current->value = **utf8_value;
current->value_length = string_value->Length();
} else { } else {
return false; if (value->IsString()) {
Handle<String> string_value = value->ToString();
NanUtf8String *utf8_value = new NanUtf8String(string_value);
resources->strings.push_back(unique_ptr<NanUtf8String>(utf8_value));
current->value = **utf8_value;
current->value_length = string_value->Length();
} else {
return false;
}
} }
array->count += 1; array->count += 1;
} }
@ -156,8 +158,7 @@ Handle<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
} }
if (EndsWith(elem->key, "-bin")) { if (EndsWith(elem->key, "-bin")) {
array->Set(index_map[elem->key], array->Set(index_map[elem->key],
MakeFastBuffer( NanNewBufferHandle(elem->value, elem->value_length));
NanNewBufferHandle(elem->value, elem->value_length)));
} else { } else {
array->Set(index_map[elem->key], NanNew(elem->value)); array->Set(index_map[elem->key], NanNew(elem->value));
} }

@ -147,7 +147,9 @@ Metadata.prototype.getMap = function() {
*/ */
Metadata.prototype.clone = function() { Metadata.prototype.clone = function() {
var copy = new Metadata(); var copy = new Metadata();
copy._internal_repr = _.cloneDeep(this._internal_repr); _.forOwn(this._internal_repr, function(value, key) {
copy._internal_repr[key] = _.clone(value);
});
return copy; return copy;
}; };

Loading…
Cancel
Save