mirror of https://github.com/grpc/grpc-node.git
				
				
				
			Make clients fail better with malformed responses
This commit is contained in:
		
							parent
							
								
									4863b70850
								
							
						
					
					
						commit
						0158f0be56
					
				|  | @ -382,6 +382,8 @@ function InterceptingCall(next_call, requester) { | ||||||
|   this.requester = requester; |   this.requester = requester; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | const emptyNext = function() {}; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Get the next method in the chain or a no-op function if we are at the end |  * Get the next method in the chain or a no-op function if we are at the end | ||||||
|  * of the chain |  * of the chain | ||||||
|  | @ -392,7 +394,7 @@ function InterceptingCall(next_call, requester) { | ||||||
| InterceptingCall.prototype._getNextCall = function(method_name) { | InterceptingCall.prototype._getNextCall = function(method_name) { | ||||||
|   return this.next_call ? |   return this.next_call ? | ||||||
|     this.next_call[method_name].bind(this.next_call) : |     this.next_call[method_name].bind(this.next_call) : | ||||||
|     function(){}; |     emptyNext; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -421,6 +423,9 @@ InterceptingCall.prototype._callNext = function(method_name, args, next) { | ||||||
|                                            next_call); |                                            next_call); | ||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|  |     if (next_call === emptyNext) { | ||||||
|  |       throw new Error('Interceptor call chain terminated unexpectedly'); | ||||||
|  |     } | ||||||
|     return next_call(args_array[0], args_array[1]); |     return next_call(args_array[0], args_array[1]); | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|  | @ -476,11 +481,11 @@ InterceptingCall.prototype.cancel = function() { | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Run a cancelWithStatus operation through the interceptor chain. |  * Run a cancelWithStatus operation through the interceptor chain. | ||||||
|  * @param {grpc~StatusObject} status |  * @param {number} code | ||||||
|  * @param {string} message |  * @param {string} details | ||||||
|  */ |  */ | ||||||
| InterceptingCall.prototype.cancelWithStatus = function(status, message) { | InterceptingCall.prototype.cancelWithStatus = function(code, details) { | ||||||
|   this._callNext('cancelWithStatus', [status, message]); |   this._callNext('cancelWithStatus', [code, details]); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -845,6 +850,9 @@ function _getUnaryInterceptor(method_definition, channel, emitter, callback) { | ||||||
|     final_requester.cancel = function () { |     final_requester.cancel = function () { | ||||||
|       call.cancel(); |       call.cancel(); | ||||||
|     }; |     }; | ||||||
|  |     final_requester.cancelWithStatus = function(code, details) { | ||||||
|  |       call.cancelWithStatus(code, details) | ||||||
|  |     }; | ||||||
|     final_requester.getPeer = function () { |     final_requester.getPeer = function () { | ||||||
|       return call.getPeer(); |       return call.getPeer(); | ||||||
|     }; |     }; | ||||||
|  | @ -957,6 +965,9 @@ function _getClientStreamingInterceptor(method_definition, channel, emitter, | ||||||
|     final_requester.cancel = function () { |     final_requester.cancel = function () { | ||||||
|       call.cancel(); |       call.cancel(); | ||||||
|     }; |     }; | ||||||
|  |     final_requester.cancelWithStatus = function(code, details) { | ||||||
|  |       call.cancelWithStatus(code, details) | ||||||
|  |     }; | ||||||
|     final_requester.getPeer = function() { |     final_requester.getPeer = function() { | ||||||
|       return call.getPeer(); |       return call.getPeer(); | ||||||
|     }; |     }; | ||||||
|  | @ -1053,6 +1064,9 @@ function _getServerStreamingInterceptor(method_definition, channel, emitter) { | ||||||
|     final_requester.cancel = function() { |     final_requester.cancel = function() { | ||||||
|       call.cancel(); |       call.cancel(); | ||||||
|     }; |     }; | ||||||
|  |     final_requester.cancelWithStatus = function(code, details) { | ||||||
|  |       call.cancelWithStatus(code, details) | ||||||
|  |     }; | ||||||
|     final_requester.getPeer = function() { |     final_requester.getPeer = function() { | ||||||
|       return call.getPeer(); |       return call.getPeer(); | ||||||
|     }; |     }; | ||||||
|  | @ -1159,6 +1173,9 @@ function _getBidiStreamingInterceptor(method_definition, channel, emitter) { | ||||||
|     final_requester.cancel = function() { |     final_requester.cancel = function() { | ||||||
|       call.cancel(); |       call.cancel(); | ||||||
|     }; |     }; | ||||||
|  |     final_requester.cancelWithStatus = function(code, details) { | ||||||
|  |       call.cancelWithStatus(code, details) | ||||||
|  |     }; | ||||||
|     final_requester.getPeer = function() { |     final_requester.getPeer = function() { | ||||||
|       return call.getPeer(); |       return call.getPeer(); | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  | @ -666,16 +666,12 @@ describe('Client malformed response handling', function() { | ||||||
|       }, |       }, | ||||||
|       serverStream: function(stream) { |       serverStream: function(stream) { | ||||||
|         stream.write(badArg); |         stream.write(badArg); | ||||||
|         stream.end(); |  | ||||||
|       }, |       }, | ||||||
|       bidiStream: function(stream) { |       bidiStream: function(stream) { | ||||||
|         stream.on('data', function() { |         stream.on('data', function() { | ||||||
|           // Ignore requests
 |           // Ignore requests
 | ||||||
|           stream.write(badArg); |           stream.write(badArg); | ||||||
|         }); |         }); | ||||||
|         stream.on('end', function() { |  | ||||||
|           stream.end(); |  | ||||||
|         }); |  | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|     var port = server.bind('localhost:0', server_insecure_creds); |     var port = server.bind('localhost:0', server_insecure_creds); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue