1919package server
2020
2121import (
22- "context"
2322 "errors"
24- "fmt"
2523 "strings"
2624
2725 "google.golang.org/grpc"
2826 "google.golang.org/grpc/codes"
2927 "google.golang.org/grpc/internal/transport"
3028 "google.golang.org/grpc/internal/xds/xdsclient/xdsresource"
3129 "google.golang.org/grpc/metadata"
32- "google.golang.org/grpc/status"
3330)
3431
3532// RouteAndProcess routes the incoming RPC to a configured route in the route
3633// table and also processes the RPC by running the incoming RPC through any HTTP
3734// Filters configured.
38- func RouteAndProcess (ctx context.Context ) error {
35+ func RouteAndProcess (ss grpc.ServerStream ) (grpc.ServerStream , error ) {
36+ ctx := ss .Context ()
3937 conn := transport .GetConnection (ctx )
4038 cw , ok := conn .(* connWrapper )
4139 if ! ok {
42- return errors .New ("missing virtual hosts in incoming context" )
40+ return nil , errors .New ("missing virtual hosts in incoming context" )
4341 }
4442
4543 rc := cw .urc .Load ()
@@ -50,28 +48,28 @@ func RouteAndProcess(ctx context.Context) error {
5048 if logger .V (2 ) {
5149 logger .Infof ("RPC on connection with xDS Configuration error: %v" , rc .err )
5250 }
53- return status . Error (codes .Unavailable , fmt . Sprintf ( "error from xDS configuration for matched route configuration: %v" , rc .err ) )
51+ return nil , rc . statusErrWithNodeID (codes .Unavailable , "error from xDS configuration for matched route configuration: %v" , rc .err )
5452 }
5553
5654 mn , ok := grpc .Method (ctx )
5755 if ! ok {
58- return errors . New ( "missing method name in incoming context" )
56+ return nil , rc . statusErrWithNodeID ( codes . Internal , "missing method name in incoming context" )
5957 }
6058 md , ok := metadata .FromIncomingContext (ctx )
6159 if ! ok {
62- return errors . New ( "missing metadata in incoming context" )
60+ return nil , rc . statusErrWithNodeID ( codes . Internal , "missing metadata in incoming context" )
6361 }
6462 // A41 added logic to the core grpc implementation to guarantee that once the
6563 // RPC gets to this point, there will be a single, unambiguous authority
6664 // present in the header map. But add a defensive check to ensure authority
6765 // header is present.
6866 authority := md .Get (":authority" )
6967 if len (authority ) == 0 {
70- return rc .statusErrWithNodeID (codes .Internal , "no :authority header present" )
68+ return nil , rc .statusErrWithNodeID (codes .Internal , "no :authority header present" )
7169 }
7270 vh := findBestMatchingVirtualHostServer (authority [0 ], rc .vhs )
7371 if vh == nil {
74- return rc .statusErrWithNodeID (codes .Unavailable , "the incoming RPC did not match a configured Virtual Host" )
72+ return nil , rc .statusErrWithNodeID (codes .Unavailable , "the incoming RPC did not match a configured Virtual Host" )
7573 }
7674
7775 var rwi * routeWithInterceptors
@@ -81,19 +79,19 @@ func RouteAndProcess(ctx context.Context) error {
8179 // server-side; a route with an inappropriate action causes RPCs
8280 // matching that route to fail with UNAVAILABLE." - A36
8381 if r .actionType != xdsresource .RouteActionNonForwardingAction {
84- return rc .statusErrWithNodeID (codes .Unavailable , "the incoming RPC matched to a route that was not of action type non forwarding" )
82+ return nil , rc .statusErrWithNodeID (codes .Unavailable , "the incoming RPC matched to a route that was not of action type non forwarding" )
8583 }
8684 rwi = & r
8785 break
8886 }
8987 }
9088 if rwi == nil {
91- return rc .statusErrWithNodeID (codes .Unavailable , "the incoming RPC did not match a configured Route" )
89+ return nil , rc .statusErrWithNodeID (codes .Unavailable , "the incoming RPC did not match a configured Route" )
9290 }
93- if err := rwi .interceptor . AllowRPC ( ctx ); err != nil {
94- return rc . statusErrWithNodeID ( codes . PermissionDenied , "Incoming RPC is not allowed: %v" , err )
91+ if rwi .interceptor != nil {
92+ return rwi . interceptor . InterceptRPC ( ss )
9593 }
96- return nil
94+ return ss , nil
9795}
9896
9997// findBestMatchingVirtualHostServer returns the virtual host whose domains field best
0 commit comments