aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/ext/node_grpc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/node/ext/node_grpc.cc')
-rw-r--r--src/node/ext/node_grpc.cc50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc
index 5b5f3c1c5b..a2b8e0d22b 100644
--- a/src/node/ext/node_grpc.cc
+++ b/src/node/ext/node_grpc.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
#include "completion_queue_async_worker.h"
#include "server_credentials.h"
+using v8::FunctionTemplate;
using v8::Local;
using v8::Value;
using v8::Object;
@@ -230,6 +231,40 @@ void InitWriteFlags(Local<Object> exports) {
Nan::Set(write_flags, Nan::New("NO_COMPRESS").ToLocalChecked(), NO_COMPRESS);
}
+NAN_METHOD(MetadataKeyIsLegal) {
+ if (!info[0]->IsString()) {
+ return Nan::ThrowTypeError(
+ "headerKeyIsLegal's argument must be a string");
+ }
+ Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
+ char *key_str = *Nan::Utf8String(key);
+ info.GetReturnValue().Set(static_cast<bool>(
+ grpc_header_key_is_legal(key_str, static_cast<size_t>(key->Length()))));
+}
+
+NAN_METHOD(MetadataNonbinValueIsLegal) {
+ if (!info[0]->IsString()) {
+ return Nan::ThrowTypeError(
+ "metadataNonbinValueIsLegal's argument must be a string");
+ }
+ Local<String> value = Nan::To<String>(info[0]).ToLocalChecked();
+ char *value_str = *Nan::Utf8String(value);
+ info.GetReturnValue().Set(static_cast<bool>(
+ grpc_header_nonbin_value_is_legal(
+ value_str, static_cast<size_t>(value->Length()))));
+}
+
+NAN_METHOD(MetadataKeyIsBinary) {
+ if (!info[0]->IsString()) {
+ return Nan::ThrowTypeError(
+ "metadataKeyIsLegal's argument must be a string");
+ }
+ Local<String> key = Nan::To<String>(info[0]).ToLocalChecked();
+ char *key_str = *Nan::Utf8String(key);
+ info.GetReturnValue().Set(static_cast<bool>(
+ grpc_is_binary_header(key_str, static_cast<size_t>(key->Length()))));
+}
+
void init(Local<Object> exports) {
Nan::HandleScope scope;
grpc_init();
@@ -247,6 +282,19 @@ void init(Local<Object> exports) {
grpc::node::Server::Init(exports);
grpc::node::CompletionQueueAsyncWorker::Init(exports);
grpc::node::ServerCredentials::Init(exports);
+
+ // Attach a few utility functions directly to the module
+ Nan::Set(exports, Nan::New("metadataKeyIsLegal").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(MetadataKeyIsLegal)).ToLocalChecked());
+ Nan::Set(exports, Nan::New("metadataNonbinValueIsLegal").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(MetadataNonbinValueIsLegal)
+ ).ToLocalChecked());
+ Nan::Set(exports, Nan::New("metadataKeyIsBinary").ToLocalChecked(),
+ Nan::GetFunction(
+ Nan::New<FunctionTemplate>(MetadataKeyIsBinary)
+ ).ToLocalChecked());
}
NODE_MODULE(grpc_node, init)