diff options
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/ext/call.cc | 10 | ||||
-rw-r--r-- | src/node/ext/call_credentials.cc | 2 | ||||
-rw-r--r-- | src/node/ext/node_grpc.cc | 50 | ||||
-rw-r--r-- | src/node/ext/timeval.cc | 2 | ||||
-rw-r--r-- | src/node/interop/async_delay_queue.js | 6 | ||||
-rw-r--r-- | src/node/interop/interop_client.js | 4 | ||||
-rw-r--r-- | src/node/interop/interop_server.js | 4 | ||||
-rw-r--r-- | src/node/jsdoc_conf.json | 6 | ||||
-rw-r--r-- | src/node/performance/benchmark_client.js | 4 | ||||
-rw-r--r-- | src/node/performance/benchmark_server.js | 4 | ||||
-rw-r--r-- | src/node/performance/worker_server.js | 4 | ||||
-rw-r--r-- | src/node/src/common.js | 4 | ||||
-rw-r--r-- | src/node/src/metadata.js | 20 | ||||
-rw-r--r-- | src/node/test/echo_service.proto | 4 | ||||
-rw-r--r-- | src/node/test/test_messages.proto | 4 | ||||
-rw-r--r-- | src/node/test/test_service.proto | 4 |
16 files changed, 90 insertions, 42 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index c6e10bc1ff..da312886ce 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.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 @@ -95,10 +95,6 @@ Local<Value> nanErrorWithCode(const char *msg, grpc_call_error code) { return scope.Escape(err); } -bool EndsWith(const char *str, const char *substr) { - return strcmp(str+strlen(str)-strlen(substr), substr) == 0; -} - bool CreateMetadataArray(Local<Object> metadata, grpc_metadata_array *array, shared_ptr<Resources> resources) { HandleScope scope; @@ -126,7 +122,7 @@ bool CreateMetadataArray(Local<Object> metadata, grpc_metadata_array *array, grpc_metadata *current = &array->metadata[array->count]; current->key = **utf8_key; // Only allow binary headers for "-bin" keys - if (EndsWith(current->key, "-bin")) { + if (grpc_is_binary_header(current->key, strlen(current->key))) { if (::node::Buffer::HasInstance(value)) { current->value = ::node::Buffer::Data(value); current->value_length = ::node::Buffer::Length(value); @@ -180,7 +176,7 @@ Local<Value> ParseMetadata(const grpc_metadata_array *metadata_array) { } else { array = Local<Array>::Cast(maybe_array.ToLocalChecked()); } - if (EndsWith(elem->key, "-bin")) { + if (grpc_is_binary_header(elem->key, strlen(elem->key))) { Nan::Set(array, index_map[elem->key], MakeFastBuffer( Nan::CopyBuffer(elem->value, diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index 8cbfb1ebea..91acb86254 100644 --- a/src/node/ext/call_credentials.cc +++ b/src/node/ext/call_credentials.cc @@ -32,6 +32,8 @@ */ #include <node.h> +#include <nan.h> +#include <uv.h> #include "grpc/grpc.h" #include "grpc/grpc_security.h" 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) diff --git a/src/node/ext/timeval.cc b/src/node/ext/timeval.cc index bf68513c48..64015e8412 100644 --- a/src/node/ext/timeval.cc +++ b/src/node/ext/timeval.cc @@ -46,7 +46,7 @@ gpr_timespec MillisecondsToTimespec(double millis) { } else if (millis == -std::numeric_limits<double>::infinity()) { return gpr_inf_past(GPR_CLOCK_REALTIME); } else { - return gpr_time_from_micros(static_cast<int64_t>(millis * 1000), + return gpr_time_from_micros(static_cast<long>(millis * 1000), GPR_CLOCK_REALTIME); } } diff --git a/src/node/interop/async_delay_queue.js b/src/node/interop/async_delay_queue.js index 2bd3ca4da3..df57209637 100644 --- a/src/node/interop/async_delay_queue.js +++ b/src/node/interop/async_delay_queue.js @@ -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 @@ -36,8 +36,8 @@ var _ = require('lodash'); /** - * This class represents a queue of callbacks that must happen sequentially, each - * with a specific delay after the previous event. + * This class represents a queue of callbacks that must happen sequentially, + * each with a specific delay after the previous event. */ function AsyncDelayQueue() { this.queue = []; diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index 53ffa385bd..db383e4d00 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -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 @@ -38,7 +38,7 @@ var path = require('path'); var grpc = require('..'); var testProto = grpc.load({ root: __dirname + '/../../..', - file: 'test/proto/test.proto'}).grpc.testing; + file: 'src/proto/grpc/testing/test.proto'}).grpc.testing; var GoogleAuth = require('google-auth-library'); var assert = require('assert'); diff --git a/src/node/interop/interop_server.js b/src/node/interop/interop_server.js index 9526b5d183..c09481712a 100644 --- a/src/node/interop/interop_server.js +++ b/src/node/interop/interop_server.js @@ -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 @@ -40,7 +40,7 @@ var AsyncDelayQueue = require('./async_delay_queue'); var grpc = require('..'); var testProto = grpc.load({ root: __dirname + '/../../..', - file: 'test/proto/test.proto'}).grpc.testing; + file: 'src/proto/grpc/testing/test.proto'}).grpc.testing; var ECHO_INITIAL_KEY = 'x-grpc-test-echo-initial'; var ECHO_TRAILING_KEY = 'x-grpc-test-echo-trailing-bin'; diff --git a/src/node/jsdoc_conf.json b/src/node/jsdoc_conf.json index 876a8e19c6..c3a0174f0e 100644 --- a/src/node/jsdoc_conf.json +++ b/src/node/jsdoc_conf.json @@ -3,13 +3,13 @@ "allowUnknownTags": true }, "source": { - "include": [ "index.js", "src" ], - "includePattern": ".+\\.js(doc)?$", + "include": [ "src/node/index.js", "src/node/src" ], + "includePattern": "src/node/.+\\.js(doc)?$", "excludePattern": "(^|\\/|\\\\)_" }, "opts": { "package": "package.json", - "readme": "README.md" + "readme": "src/node/README.md" }, "plugins": [], "templates": { diff --git a/src/node/performance/benchmark_client.js b/src/node/performance/benchmark_client.js index d97bdbbcaf..620aecde97 100644 --- a/src/node/performance/benchmark_client.js +++ b/src/node/performance/benchmark_client.js @@ -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 @@ -48,7 +48,7 @@ var Histogram = require('./histogram'); var grpc = require('../../../'); var serviceProto = grpc.load({ root: __dirname + '/../../..', - file: 'test/proto/benchmarks/services.proto'}).grpc.testing; + file: 'src/proto/grpc/testing/services.proto'}).grpc.testing; /** * Create a buffer filled with size zeroes diff --git a/src/node/performance/benchmark_server.js b/src/node/performance/benchmark_server.js index ac96fc5edb..ba61e52ba1 100644 --- a/src/node/performance/benchmark_server.js +++ b/src/node/performance/benchmark_server.js @@ -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,7 +44,7 @@ var path = require('path'); var grpc = require('../../../'); var serviceProto = grpc.load({ root: __dirname + '/../../..', - file: 'test/proto/benchmarks/services.proto'}).grpc.testing; + file: 'src/proto/grpc/testing/services.proto'}).grpc.testing; /** * Create a buffer filled with size zeroes diff --git a/src/node/performance/worker_server.js b/src/node/performance/worker_server.js index 43b86e5ecf..7c8ab00026 100644 --- a/src/node/performance/worker_server.js +++ b/src/node/performance/worker_server.js @@ -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 @@ -38,7 +38,7 @@ var worker_service_impl = require('./worker_service_impl'); var grpc = require('../../../'); var serviceProto = grpc.load({ root: __dirname + '/../../..', - file: 'test/proto/benchmarks/services.proto'}).grpc.testing; + file: 'src/proto/grpc/testing/services.proto'}).grpc.testing; function runServer(port) { var server_creds = grpc.ServerCredentials.createInsecure(); diff --git a/src/node/src/common.js b/src/node/src/common.js index e4fe5a8e03..2e6c01c4d7 100644 --- a/src/node/src/common.js +++ b/src/node/src/common.js @@ -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 @@ -125,7 +125,7 @@ exports.getProtobufServiceAttrs = function getProtobufServiceAttrs(service) { var prefix = '/' + fullyQualifiedName(service) + '/'; return _.object(_.map(service.children, function(method) { return [_.camelCase(method.name), { - path: prefix + _.capitalize(method.name), + path: prefix + method.name, requestStream: method.requestStream, responseStream: method.responseStream, requestSerialize: serializeCls(method.resolvedRequestType.build()), diff --git a/src/node/src/metadata.js b/src/node/src/metadata.js index 0a2f1489b6..fef79f959e 100644 --- a/src/node/src/metadata.js +++ b/src/node/src/metadata.js @@ -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 @@ -49,6 +49,8 @@ var _ = require('lodash'); +var grpc = require('bindings')('grpc_node'); + /** * Class for storing metadata. Keys are normalized to lowercase ASCII. * @constructor @@ -58,15 +60,16 @@ function Metadata() { } function normalizeKey(key) { - if (!(/^[A-Za-z\d_-]+$/.test(key))) { - throw new Error('Metadata keys must be nonempty strings containing only ' + - 'alphanumeric characters and hyphens'); + key = key.toLowerCase(); + if (grpc.metadataKeyIsLegal(key)) { + return key; + } else { + throw new Error('Metadata key contains illegal characters'); } - return key.toLowerCase(); } function validate(key, value) { - if (_.endsWith(key, '-bin')) { + if (grpc.metadataKeyIsBinary(key)) { if (!(value instanceof Buffer)) { throw new Error('keys that end with \'-bin\' must have Buffer values'); } @@ -75,9 +78,8 @@ function validate(key, value) { throw new Error( 'keys that don\'t end with \'-bin\' must have String values'); } - if (!(/^[\x20-\x7E]*$/.test(value))) { - throw new Error('Metadata string values can only contain printable ' + - 'ASCII characters and space'); + if (!grpc.metadataNonbinValueIsLegal(value)) { + throw new Error('Metadata string value contains illegal characters'); } } } diff --git a/src/node/test/echo_service.proto b/src/node/test/echo_service.proto index b2c7e3dc23..11b4f18c35 100644 --- a/src/node/test/echo_service.proto +++ b/src/node/test/echo_service.proto @@ -1,4 +1,4 @@ -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -36,4 +36,4 @@ message EchoMessage { service EchoService { rpc Echo (EchoMessage) returns (EchoMessage); -}
\ No newline at end of file +} diff --git a/src/node/test/test_messages.proto b/src/node/test/test_messages.proto index 685e9482bd..c77a937d3f 100644 --- a/src/node/test/test_messages.proto +++ b/src/node/test/test_messages.proto @@ -1,4 +1,4 @@ -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -35,4 +35,4 @@ message LongValues { sint64 sint_64 = 3; fixed64 fixed_64 = 4; sfixed64 sfixed_64 = 5; -}
\ No newline at end of file +} diff --git a/src/node/test/test_service.proto b/src/node/test/test_service.proto index 564169829c..0ac2ae79a7 100644 --- a/src/node/test/test_service.proto +++ b/src/node/test/test_service.proto @@ -1,4 +1,4 @@ -// Copyright 2015, Google Inc. +// Copyright 2015-2016, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -49,4 +49,4 @@ service TestService { rpc BidiStream (stream Request) returns (stream Response) { } -}
\ No newline at end of file +} |