Socket
Socket
Sign inDemoInstall

grpc-server-js

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc-server-js - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

lib/options.js

8

lib/handler.js

@@ -166,2 +166,3 @@ 'use strict';

const decoder = new StreamDecoder();
const { maxReceiveMessageLength } = stream[kCall];

@@ -187,2 +188,9 @@ stream[kReadableState] = {

for (let i = 0; i < messages.length; i++) {
if (messages[i].length > maxReceiveMessageLength) {
const err = new Error('Received message larger than max ' +
`(${messages[i].length} vs. ${maxReceiveMessageLength})`);
stream[kCall].sendError(err, Status.RESOURCE_EXHAUSTED);
return;
}
stream[kReadablePushOrBufferMessage](messages[i]);

@@ -189,0 +197,0 @@ }

2

lib/index.d.ts

@@ -177,2 +177,4 @@ /// <reference types="node" />

'grpc.use_local_subchannel_pool'?: number;
'grpc.max_send_message_length'?: number;
'grpc.max_receive_message_length'?: number;
[key: string]: string | number | undefined;

@@ -179,0 +181,0 @@ }

31

lib/server-call.js

@@ -31,3 +31,3 @@ 'use strict';

class ServerCall extends EventEmitter {
constructor (stream) {
constructor (stream, options) {
super();

@@ -41,2 +41,4 @@ this.handler = null;

this.status = { code: Status.OK, details: 'OK', metadata: null };
this.maxSendMessageLength = options.maxSendMessageLength;
this.maxReceiveMessageLength = options.maxReceiveMessageLength;
this.stream.on('drain', onStreamDrain.bind(this));

@@ -109,2 +111,9 @@ this.stream.once('error', onStreamError.bind(this));

stream.once('end', async () => {
if (totalLength > this.maxReceiveMessageLength) {
const err = new Error('Received message larger than max ' +
`(${totalLength} vs. ${this.maxReceiveMessageLength})`);
this.sendError(err, Status.RESOURCE_EXHAUSTED);
return;
}
try {

@@ -150,3 +159,4 @@ const requestBytes = Buffer.concat(chunks, totalLength);

this.end(response);
this.write(response);
this.stream.end();
} catch (err) {

@@ -188,2 +198,9 @@ this.sendError(err, Status.INTERNAL);

if (chunk.length > this.maxSendMessageLength) {
const err = new Error('Sent message larger than max ' +
`(${chunk.length} vs. ${this.maxSendMessageLength})`);
this.sendError(err, Status.RESOURCE_EXHAUSTED);
return;
}
this.sendMetadata();

@@ -193,3 +210,3 @@ return this.stream.write(chunk);

end (payload) {
end () {
if (this.cancelled === true || this.stream.destroyed === true) {

@@ -199,9 +216,4 @@ return;

if (this.deadline !== null) {
clearTimeout(this.deadline);
this.deadline = null;
}
this.sendMetadata();
return this.stream.end(payload);
return this.stream.end();
}

@@ -245,2 +257,3 @@ }

clearTimeout(this.deadline);
this.stream.sendTrailers(trailersToSend);

@@ -247,0 +260,0 @@ }

@@ -9,2 +9,3 @@ 'use strict';

} = require('./handler');
const { parseOptions } = require('./options');
const { ServerCall } = require('./server-call');

@@ -20,3 +21,2 @@ const { ServerCredentials } = require('./server-credentials');

const kSessions = Symbol('sessions');
const kSessionOptions = Symbol('sessionOptions');
const kUnaryHandlerType = 0;

@@ -34,2 +34,3 @@ const kClientStreamHandlerType = 1;

} = Http2.constants;
const defaultHttp2Settings = Http2.getDefaultSettings();

@@ -43,11 +44,3 @@ const unsuportedMediaTypeResponse = {

const defaultHttp2Settings = Http2.getDefaultSettings();
const defaultServerOptions = {
'grpc.max_concurrent_streams': undefined,
'grpc.http2.max_frame_size': defaultHttp2Settings.maxFrameSize,
'grpc.keepalive_time_ms': 7200000, // 2 hours in ms (spec default).
'grpc.keepalive_timeout_ms': 20000 // 20 seconds in ms (spec default).
};
class Server {

@@ -63,7 +56,3 @@ constructor (options = {}) {

this[kStarted] = false;
this[kOptions] = { ...defaultServerOptions, ...options };
this[kSessionOptions] = {
keepaliveTimeMs: this[kOptions]['grpc.keepalive_time_ms'],
keepaliveTimeoutMs: this[kOptions]['grpc.keepalive_timeout_ms']
};
this[kOptions] = parseOptions(options);
}

@@ -118,4 +107,4 @@

enablePush: false,
maxFrameSize: this[kOptions]['grpc.http2.max_frame_size'],
maxConcurrentStreams: this[kOptions]['grpc.max_concurrent_streams']
maxFrameSize: this[kOptions].maxFrameSize,
maxConcurrentStreams: this[kOptions].maxConcurrentStreams
}

@@ -319,3 +308,3 @@ };

const call = new ServerCall(stream);
const call = new ServerCall(stream, grpcServer[kOptions]);

@@ -345,3 +334,3 @@ try {

const grpcSession = new ServerSession(session, grpcServer[kSessionOptions]);
const grpcSession = new ServerSession(session, grpcServer[kOptions]);

@@ -348,0 +337,0 @@ // The client has connected, so begin sending keepalive pings.

{
"name": "grpc-server-js",
"version": "0.2.2",
"version": "0.3.0",
"description": "Pure JavaScript gRPC Server",

@@ -5,0 +5,0 @@ "author": "Colin J. Ihrig <cjihrig@gmail.com> (http://www.cjihrig.com/)",

@@ -32,2 +32,4 @@ # grpc-server-js

- `grpc.max_concurrent_streams`
- `grpc.max_receive_message_length`
- `grpc.max_send_message_length`
- All possible options and their descriptions are available [here](https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h).

@@ -34,0 +36,0 @@ - Supports the following gRPC environment variables:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc