Added metadata pass-through to server method handlers

pull/283/head
murgatroid99 10 years ago
parent 7f791669df
commit 684f6f4359
  1. 34
      src/node/src/surface_server.js

@ -129,16 +129,18 @@ ServerWritableObjectStream.prototype._write = _write;
/** /**
* Creates a binary stream handler function from a unary handler function * Creates a binary stream handler function from a unary handler function
* @param {function(Object, function(Error, *))} handler Unary call handler * @param {function(Object, function(Error, *), metadata=)} handler Unary call
* @return {function(stream)} Binary stream handler * handler
* @return {function(stream, metadata=)} Binary stream handler
*/ */
function makeUnaryHandler(handler) { function makeUnaryHandler(handler) {
/** /**
* Handles a stream by reading a single data value, passing it to the handler, * Handles a stream by reading a single data value, passing it to the handler,
* and writing the response back to the stream. * and writing the response back to the stream.
* @param {stream} stream Binary data stream * @param {stream} stream Binary data stream
* @param {metadata=} metadata Incoming metadata array
*/ */
return function handleUnaryCall(stream) { return function handleUnaryCall(stream, metadata) {
stream.on('data', function handleUnaryData(value) { stream.on('data', function handleUnaryData(value) {
var call = {request: value}; var call = {request: value};
Object.defineProperty(call, 'cancelled', { Object.defineProperty(call, 'cancelled', {
@ -154,7 +156,7 @@ function makeUnaryHandler(handler) {
stream.write(value); stream.write(value);
stream.end(); stream.end();
} }
}); }, metadata);
}); });
}; };
} }
@ -162,17 +164,18 @@ function makeUnaryHandler(handler) {
/** /**
* Creates a binary stream handler function from a client stream handler * Creates a binary stream handler function from a client stream handler
* function * function
* @param {function(Readable, function(Error, *))} handler Client stream call * @param {function(Readable, function(Error, *), metadata=)} handler Client
* handler * stream call handler
* @return {function(stream)} Binary stream handler * @return {function(stream, metadata=)} Binary stream handler
*/ */
function makeClientStreamHandler(handler) { function makeClientStreamHandler(handler) {
/** /**
* Handles a stream by passing a deserializing stream to the handler and * Handles a stream by passing a deserializing stream to the handler and
* writing the response back to the stream. * writing the response back to the stream.
* @param {stream} stream Binary data stream * @param {stream} stream Binary data stream
* @param {metadata=} metadata Incoming metadata array
*/ */
return function handleClientStreamCall(stream) { return function handleClientStreamCall(stream, metadata) {
var object_stream = new ServerReadableObjectStream(stream); var object_stream = new ServerReadableObjectStream(stream);
handler(object_stream, function sendClientStreamData(err, value) { handler(object_stream, function sendClientStreamData(err, value) {
if (err) { if (err) {
@ -181,35 +184,36 @@ function makeClientStreamHandler(handler) {
stream.write(value); stream.write(value);
stream.end(); stream.end();
} }
}); }, metadata);
}; };
} }
/** /**
* Creates a binary stream handler function from a server stream handler * Creates a binary stream handler function from a server stream handler
* function * function
* @param {function(Writable)} handler Server stream call handler * @param {function(Writable, metadata=)} handler Server stream call handler
* @return {function(stream)} Binary stream handler * @return {function(stream, metadata=)} Binary stream handler
*/ */
function makeServerStreamHandler(handler) { function makeServerStreamHandler(handler) {
/** /**
* Handles a stream by attaching it to a serializing stream, and passing it to * Handles a stream by attaching it to a serializing stream, and passing it to
* the handler. * the handler.
* @param {stream} stream Binary data stream * @param {stream} stream Binary data stream
* @param {metadata=} metadata Incoming metadata array
*/ */
return function handleServerStreamCall(stream) { return function handleServerStreamCall(stream, metadata) {
stream.on('data', function handleClientData(value) { stream.on('data', function handleClientData(value) {
var object_stream = new ServerWritableObjectStream(stream); var object_stream = new ServerWritableObjectStream(stream);
object_stream.request = value; object_stream.request = value;
handler(object_stream); handler(object_stream, metadata);
}); });
}; };
} }
/** /**
* Creates a binary stream handler function from a bidi stream handler function * Creates a binary stream handler function from a bidi stream handler function
* @param {function(Duplex)} handler Unary call handler * @param {function(Duplex, metadata=)} handler Unary call handler
* @return {function(stream)} Binary stream handler * @return {function(stream, metadata=)} Binary stream handler
*/ */
function makeBidiStreamHandler(handler) { function makeBidiStreamHandler(handler) {
return handler; return handler;

Loading…
Cancel
Save