@@ -449,6 +449,33 @@ func (s *GrpcWebWrapperTestSuite) TestCORSPreflight_AllowedByOriginFunc() {
449449 assert .Equal (s .T (), 500 , corsResp .StatusCode , "cors should return 500 as grpc server does not understand that endpoint" )
450450}
451451
452+ func (s * GrpcWebWrapperTestSuite ) TestCORSPreflight_CorsMaxAge () {
453+ /**
454+ OPTIONS /improbable.grpcweb.test.TestService/Ping
455+ Access-Control-Request-Method: POST
456+ Access-Control-Request-Headers: origin, x-requested-with, accept
457+ Origin: http://foo.client.com
458+ */
459+ headers := http.Header {}
460+ headers .Add ("Access-Control-Request-Method" , "POST" )
461+ headers .Add ("Access-Control-Request-Headers" , "origin, x-something-custom, x-grpc-web, accept" )
462+ headers .Add ("Origin" , "https://foo.client.com" )
463+
464+ // Create a new server which customizes a cache time of the preflight request to a Cross-Origin Resource.
465+ s .wrappedServer = grpcweb .WrapServer (s .grpcServer ,
466+ grpcweb .WithOriginFunc (func (string ) bool {
467+ return true
468+ }),
469+ grpcweb .WithCorsMaxAge (time .Hour ),
470+ )
471+
472+ corsResp , err := s .makeRequest ("OPTIONS" , "/improbable.grpcweb.test.TestService/PingList" , headers , nil , false )
473+ assert .NoError (s .T (), err , "cors preflight should not return errors" )
474+
475+ preflight := corsResp .Header
476+ assert .Equal (s .T (), "3600" , preflight .Get ("Access-Control-Max-Age" ), "allowed max age must be in the response headers" )
477+ }
478+
452479func (s * GrpcWebWrapperTestSuite ) TestCORSPreflight_EndpointsOnlyTrueWithHandlerFunc () {
453480 /**
454481 OPTIONS /improbable.grpcweb.test.TestService/Ping
0 commit comments