@@ -603,38 +603,46 @@ private void createStream(CreateStreamCommand command, ChannelPromise promise)
603603 return ;
604604 }
605605
606- CharSequence authority = command .headers ().authority ();
607- if (authority != null ) {
608- Status authorityVerificationStatus = peerVerificationResults .get (authority .toString ());
609- if (authorityVerificationStatus == null ) {
610- if (attributes != null
611- && attributes .get (GrpcAttributes .ATTR_AUTHORITY_VERIFIER ) != null ) {
612- authorityVerificationStatus = attributes .get (GrpcAttributes .ATTR_AUTHORITY_VERIFIER )
613- .verifyAuthority (authority .toString ());
614- peerVerificationResults .put (authority .toString (), authorityVerificationStatus );
615- if (!authorityVerificationStatus .isOk () && !enablePerRpcAuthorityCheck ) {
616- logger .log (Level .WARNING , String .format ("%s.%s" ,
617- authorityVerificationStatus .getDescription (), enablePerRpcAuthorityCheck
618- ? "" : " This will be an error in the future." ),
619- InternalStatus .asRuntimeExceptionWithoutStacktrace (authorityVerificationStatus , null ));
606+ CharSequence authorityHeader = command .headers ().authority ();
607+ if (authorityHeader != null ) {
608+ // No need to verify authority for the rpc outgoing header if it is same as the authority
609+ // for the transport
610+ if (!authority .contentEquals (authorityHeader )) {
611+ Status authorityVerificationStatus = peerVerificationResults .get (
612+ authorityHeader .toString ());
613+ if (authorityVerificationStatus == null ) {
614+ if (attributes .get (GrpcAttributes .ATTR_AUTHORITY_VERIFIER ) != null ) {
615+ authorityVerificationStatus = attributes .get (GrpcAttributes .ATTR_AUTHORITY_VERIFIER )
616+ .verifyAuthority (authorityHeader .toString ());
617+ peerVerificationResults .put (authorityHeader .toString (), authorityVerificationStatus );
618+ if (!authorityVerificationStatus .isOk () && !enablePerRpcAuthorityCheck ) {
619+ logger .log (Level .WARNING , String .format ("%s.%s" ,
620+ authorityVerificationStatus .getDescription (),
621+ enablePerRpcAuthorityCheck
622+ ? "" : " This will be an error in the future." ),
623+ InternalStatus .asRuntimeExceptionWithoutStacktrace (
624+ authorityVerificationStatus , null ));
625+ }
626+ } else {
627+ authorityVerificationStatus = Status .UNAVAILABLE .withDescription (
628+ "Authority verifier not found to verify authority" );
629+ command .stream ().setNonExistent ();
630+ command .stream ().transportReportStatus (
631+ authorityVerificationStatus , RpcProgress .PROCESSED , true , new Metadata ());
632+ promise .setFailure (InternalStatus .asRuntimeExceptionWithoutStacktrace (
633+ authorityVerificationStatus , null ));
634+ return ;
620635 }
621- } else {
622- authorityVerificationStatus = Status .UNAVAILABLE .withDescription (
623- "Authority verifier not found to verify authority" );
624- command .stream ().setNonExistent ();
625- command .stream ().transportReportStatus (
626- authorityVerificationStatus , RpcProgress .DROPPED , true , new Metadata ());
627- promise .setFailure (InternalStatus .asRuntimeExceptionWithoutStacktrace (authorityVerificationStatus , null ));
628- return ;
629636 }
630- }
631- if (authorityVerificationStatus != null && !authorityVerificationStatus .isOk ()) {
632- if (enablePerRpcAuthorityCheck ) {
633- command .stream ().setNonExistent ();
634- command .stream ().transportReportStatus (
635- authorityVerificationStatus , RpcProgress .DROPPED , true , new Metadata ());
636- promise .setFailure (InternalStatus .asRuntimeExceptionWithoutStacktrace (authorityVerificationStatus , null ));
637- return ;
637+ if (authorityVerificationStatus != null && !authorityVerificationStatus .isOk ()) {
638+ if (enablePerRpcAuthorityCheck ) {
639+ command .stream ().setNonExistent ();
640+ command .stream ().transportReportStatus (
641+ authorityVerificationStatus , RpcProgress .PROCESSED , true , new Metadata ());
642+ promise .setFailure (InternalStatus .asRuntimeExceptionWithoutStacktrace (
643+ authorityVerificationStatus , null ));
644+ return ;
645+ }
638646 }
639647 }
640648 } else {
@@ -643,7 +651,8 @@ private void createStream(CreateStreamCommand command, ChannelPromise promise)
643651 command .stream ().setNonExistent ();
644652 command .stream ().transportReportStatus (
645653 Status .UNAVAILABLE , RpcProgress .DROPPED , true , new Metadata ());
646- promise .setFailure (InternalStatus .asRuntimeExceptionWithoutStacktrace (authorityVerificationStatus , null ));
654+ promise .setFailure (InternalStatus .asRuntimeExceptionWithoutStacktrace (
655+ authorityVerificationStatus , null ));
647656 return ;
648657 }
649658 // Get the stream ID for the new stream.
0 commit comments