@@ -546,6 +546,7 @@ export class BaseServerInterceptingCall
546546 private connectionInfo : ConnectionInfo ;
547547 private metricsRecorder = new PerRequestMetricRecorder ( ) ;
548548 private shouldSendMetrics : boolean ;
549+ private allowedOrigin ?: string ;
549550
550551 constructor (
551552 private readonly stream : http2 . ServerHttp2Stream ,
@@ -598,6 +599,9 @@ export class BaseServerInterceptingCall
598599 if ( 'grpc.max_receive_message_length' in options ) {
599600 this . maxReceiveMessageSize = options [ 'grpc.max_receive_message_length' ] ! ;
600601 }
602+ if ( 'grpc.allow_origin' in options ) {
603+ this . allowedOrigin = options [ 'grpc.allow_origin' ] ! ;
604+ }
601605
602606 this . host = headers [ ':authority' ] ?? headers . host ! ;
603607 this . decoder = new StreamDecoder ( this . maxReceiveMessageSize ) ;
@@ -877,10 +881,17 @@ export class BaseServerInterceptingCall
877881
878882 this . metadataSent = true ;
879883 const custom = metadata ? metadata . toHttp2Headers ( ) : null ;
884+ const allowedOriginHeader = this . allowedOrigin
885+ ? {
886+ [ http2 . constants . HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN ] :
887+ this . allowedOrigin ,
888+ }
889+ : null ;
880890 const headers = {
881891 ...defaultResponseHeaders ,
882892 ...defaultCompressionHeaders ,
883893 ...custom ,
894+ ...allowedOriginHeader ,
884895 } ;
885896 this . stream . respond ( headers , defaultResponseOptions ) ;
886897 }
@@ -978,12 +989,21 @@ export class BaseServerInterceptingCall
978989 this . callEventTracker . onStreamEnd ( true ) ;
979990 this . callEventTracker . onCallEnd ( status ) ;
980991 }
992+
993+ const allowedOriginHeader = this . allowedOrigin
994+ ? {
995+ [ http2 . constants . HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN ] :
996+ this . allowedOrigin ,
997+ }
998+ : null ;
999+
9811000 // Trailers-only response
9821001 const trailersToSend : http2 . OutgoingHttpHeaders = {
9831002 [ GRPC_STATUS_HEADER ] : status . code ,
9841003 [ GRPC_MESSAGE_HEADER ] : encodeURI ( status . details ) ,
9851004 ...defaultResponseHeaders ,
9861005 ...statusMetadata . toHttp2Headers ( ) ,
1006+ ...allowedOriginHeader ,
9871007 } ;
9881008 this . stream . respond ( trailersToSend , { endStream : true } ) ;
9891009 this . notifyOnCancel ( ) ;
0 commit comments