aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/ext/call.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/node/ext/call.cc')
-rw-r--r--src/node/ext/call.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc
index b08a9f96d8..b63e294f9a 100644
--- a/src/node/ext/call.cc
+++ b/src/node/ext/call.cc
@@ -39,12 +39,14 @@
#include "grpc/support/log.h"
#include "grpc/grpc.h"
+#include "grpc/grpc_security.h"
#include "grpc/support/alloc.h"
#include "grpc/support/time.h"
#include "byte_buffer.h"
#include "call.h"
#include "channel.h"
#include "completion_queue_async_worker.h"
+#include "call_credentials.h"
#include "timeval.h"
using std::unique_ptr;
@@ -168,8 +170,9 @@ Local<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
}
if (EndsWith(elem->key, "-bin")) {
Nan::Set(array, index_map[elem->key],
- Nan::CopyBuffer(elem->value,
- elem->value_length).ToLocalChecked());
+ MakeFastBuffer(
+ Nan::CopyBuffer(elem->value,
+ elem->value_length).ToLocalChecked()));
} else {
Nan::Set(array, index_map[elem->key],
Nan::New(elem->value).ToLocalChecked());
@@ -501,6 +504,7 @@ void Call::Init(Local<Object> exports) {
Nan::SetPrototypeMethod(tpl, "cancel", Cancel);
Nan::SetPrototypeMethod(tpl, "cancelWithStatus", CancelWithStatus);
Nan::SetPrototypeMethod(tpl, "getPeer", GetPeer);
+ Nan::SetPrototypeMethod(tpl, "setCredentials", SetCredentials);
fun_tpl.Reset(tpl);
Local<Function> ctr = Nan::GetFunction(tpl).ToLocalChecked();
Nan::Set(exports, Nan::New("Call").ToLocalChecked(), ctr);
@@ -724,5 +728,26 @@ NAN_METHOD(Call::GetPeer) {
info.GetReturnValue().Set(peer_value);
}
+NAN_METHOD(Call::SetCredentials) {
+ Nan::HandleScope scope;
+ if (!HasInstance(info.This())) {
+ return Nan::ThrowTypeError(
+ "setCredentials can only be called on Call objects");
+ }
+ if (!CallCredentials::HasInstance(info[0])) {
+ return Nan::ThrowTypeError(
+ "setCredentials' first argument must be a CallCredentials");
+ }
+ Call *call = ObjectWrap::Unwrap<Call>(info.This());
+ CallCredentials *creds_object = ObjectWrap::Unwrap<CallCredentials>(
+ Nan::To<Object>(info[0]).ToLocalChecked());
+ grpc_credentials *creds = creds_object->GetWrappedCredentials();
+ grpc_call_error error = GRPC_CALL_ERROR;
+ if (creds) {
+ error = grpc_call_set_credentials(call->wrapped_call, creds);
+ }
+ info.GetReturnValue().Set(Nan::New<Uint32>(error));
+}
+
} // namespace node
} // namespace grpc