@@ -7847,3 +7847,40 @@ func (s) TestStreamingServerInterceptorGetsConnection(t *testing.T) {
7847
7847
t .Fatalf ("ss.Client.StreamingInputCall(_) = _, %v, want _, %v" , err , io .EOF )
7848
7848
}
7849
7849
}
7850
+
7851
+ func unaryInterceptorVerifyPost (ctx context.Context , req interface {}, info * grpc.UnaryServerInfo , handler grpc.UnaryHandler ) (interface {}, error ) {
7852
+ md , ok := metadata .FromIncomingContext (ctx )
7853
+ if ! ok {
7854
+ return nil , status .Error (codes .NotFound , "metadata was not in context" )
7855
+ }
7856
+ method := md .Get (":method" )
7857
+ if len (method ) != 1 {
7858
+ return nil , status .Error (codes .InvalidArgument , ":method value had more than one value" )
7859
+ }
7860
+ if method [0 ] != "POST" {
7861
+ return nil , status .Error (codes .InvalidArgument , ":method value was not post" )
7862
+ }
7863
+ return handler (ctx , req )
7864
+ }
7865
+
7866
+ // TestUnaryInterceptorGetsPost verifies that the server transport adds a
7867
+ // :method POST header to metadata, and that that added Header is visibile at
7868
+ // the grpc layer.
7869
+ func (s ) TestUnaryInterceptorGetsPost (t * testing.T ) {
7870
+ ss := & stubserver.StubServer {
7871
+ EmptyCallF : func (ctx context.Context , in * testpb.Empty ) (* testpb.Empty , error ) {
7872
+ return & testpb.Empty {}, nil
7873
+ },
7874
+ }
7875
+ if err := ss .Start ([]grpc.ServerOption {grpc .UnaryInterceptor (unaryInterceptorVerifyPost )}); err != nil {
7876
+ t .Fatalf ("Error starting endpoint server: %v" , err )
7877
+ }
7878
+ defer ss .Stop ()
7879
+
7880
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
7881
+ defer cancel ()
7882
+
7883
+ if _ , err := ss .Client .EmptyCall (ctx , & testpb.Empty {}); status .Code (err ) != codes .OK {
7884
+ t .Fatalf ("ss.Client.EmptyCall(_, _) = _, %v, want _, error code %s" , err , codes .OK )
7885
+ }
7886
+ }
0 commit comments