@@ -380,19 +380,18 @@ function Client(address, credentials, options) {
380380 options [ 'grpc.primary_user_agent' ] += 'grpc-node/' + version ;
381381
382382 // Resolve interceptor options and assign interceptors to each method
383- var interceptor_providers = options . interceptor_providers || [ ] ;
384- var interceptors = options . interceptors || [ ] ;
385- if ( interceptor_providers . length && interceptors . length ) {
383+ if ( _ . isArray ( options . interceptor_providers ) && _ . isArray ( options . interceptors ) ) {
386384 throw new client_interceptors . InterceptorConfigurationError (
387385 'Both interceptors and interceptor_providers were passed as options ' +
388386 'to the client constructor. Only one of these is allowed.' ) ;
389387 }
388+ self . $interceptors = options . interceptors || [ ] ;
389+ self . $interceptor_providers = options . interceptor_providers || [ ] ;
390390 _ . each ( self . $method_definitions , function ( method_definition , method_name ) {
391391 self [ method_name ] . interceptors = client_interceptors
392- . resolveInterceptorProviders ( interceptor_providers , method_definition )
393- . concat ( interceptors ) ;
392+ . resolveInterceptorProviders ( self . $ interceptor_providers, method_definition )
393+ . concat ( self . $ interceptors) ;
394394 } ) ;
395-
396395 // Exclude interceptor options which have already been consumed
397396 var channel_options = _ . omit ( options ,
398397 [ 'interceptors' , 'interceptor_providers' ] ) ;
@@ -403,6 +402,21 @@ function Client(address, credentials, options) {
403402
404403exports . Client = Client ;
405404
405+ Client . prototype . resolveCallInterceptors = function ( method_definition , interceptors , interceptor_providers ) {
406+ if ( _ . isArray ( interceptors ) && _ . isArray ( interceptor_providers ) ) {
407+ throw new client_interceptors . InterceptorConfigurationError (
408+ 'Both interceptors and interceptor_providers were passed as call ' +
409+ 'options. Only one of these is allowed.' ) ;
410+ }
411+ if ( _ . isArray ( interceptors ) || _ . isArray ( interceptor_providers ) ) {
412+ interceptors = interceptors || [ ] ;
413+ interceptor_providers = interceptor_providers || [ ] ;
414+ return client_interceptors . resolveInterceptorProviders ( interceptor_providers , method_definition ) . concat ( interceptors ) ;
415+ } else {
416+ return client_interceptors . resolveInterceptorProviders ( this . $interceptor_providers , method_definition ) . concat ( this . $interceptors ) ;
417+ }
418+ }
419+
406420/**
407421 * @callback grpc.Client~requestCallback
408422 * @param {?grpc~ServiceError } error The error, if the call
@@ -454,10 +468,6 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize,
454468 throw new Error ( 'Argument mismatch in makeUnaryRequest' ) ;
455469 }
456470
457- var method_name = this . $method_names [ path ] ;
458- var constructor_interceptors = this [ method_name ] ?
459- this [ method_name ] . interceptors :
460- null ;
461471 var method_definition = options . method_definition = {
462472 path : path ,
463473 requestStream : false ,
@@ -471,7 +481,7 @@ Client.prototype.makeUnaryRequest = function(path, serialize, deserialize,
471481 var intercepting_call = client_interceptors . getInterceptingCall (
472482 method_definition ,
473483 options ,
474- constructor_interceptors ,
484+ Client . prototype . resolveCallInterceptors . call ( this , method_definition , options . interceptors , options . interceptor_providers ) ,
475485 this . $channel ,
476486 callback
477487 ) ;
@@ -533,10 +543,6 @@ Client.prototype.makeClientStreamRequest = function(path, serialize,
533543 throw new Error ( 'Argument mismatch in makeClientStreamRequest' ) ;
534544 }
535545
536- var method_name = this . $method_names [ path ] ;
537- var constructor_interceptors = this [ method_name ] ?
538- this [ method_name ] . interceptors :
539- null ;
540546 var method_definition = options . method_definition = {
541547 path : path ,
542548 requestStream : true ,
@@ -550,7 +556,7 @@ Client.prototype.makeClientStreamRequest = function(path, serialize,
550556 var intercepting_call = client_interceptors . getInterceptingCall (
551557 method_definition ,
552558 options ,
553- constructor_interceptors ,
559+ Client . prototype . resolveCallInterceptors . call ( this , method_definition , options . interceptors , options . interceptor_providers ) ,
554560 this . $channel ,
555561 callback
556562 ) ;
@@ -595,10 +601,6 @@ Client.prototype.makeServerStreamRequest = function(path, serialize,
595601 throw new Error ( 'Argument mismatch in makeServerStreamRequest' ) ;
596602 }
597603
598- var method_name = this . $method_names [ path ] ;
599- var constructor_interceptors = this [ method_name ] ?
600- this [ method_name ] . interceptors :
601- null ;
602604 var method_definition = options . method_definition = {
603605 path : path ,
604606 requestStream : false ,
@@ -613,7 +615,7 @@ Client.prototype.makeServerStreamRequest = function(path, serialize,
613615 var intercepting_call = client_interceptors . getInterceptingCall (
614616 method_definition ,
615617 options ,
616- constructor_interceptors ,
618+ Client . prototype . resolveCallInterceptors . call ( this , method_definition , options . interceptors , options . interceptor_providers ) ,
617619 this . $channel ,
618620 emitter
619621 ) ;
@@ -655,10 +657,6 @@ Client.prototype.makeBidiStreamRequest = function(path, serialize,
655657 throw new Error ( 'Argument mismatch in makeBidiStreamRequest' ) ;
656658 }
657659
658- var method_name = this . $method_names [ path ] ;
659- var constructor_interceptors = this [ method_name ] ?
660- this [ method_name ] . interceptors :
661- null ;
662660 var method_definition = options . method_definition = {
663661 path : path ,
664662 requestStream : true ,
@@ -673,7 +671,7 @@ Client.prototype.makeBidiStreamRequest = function(path, serialize,
673671 var intercepting_call = client_interceptors . getInterceptingCall (
674672 method_definition ,
675673 options ,
676- constructor_interceptors ,
674+ Client . prototype . resolveCallInterceptors . call ( this , method_definition , options . interceptors , options . interceptor_providers ) ,
677675 this . $channel ,
678676 emitter
679677 ) ;
0 commit comments