@@ -4602,6 +4602,7 @@ func (s) TestZeroSecondTimeout(t *testing.T) {
46024602 BlockFragment : st .encodeHeader (
46034603 ":method" , "POST" ,
46044604 ":path" , "/grpc.testing.TestService/StreamingInputCall" ,
4605+ ":authority" , "localhost" ,
46054606 "content-type" , "application/grpc" ,
46064607 "te" , "trailers" ,
46074608 "grpc-timeout" , "0n" ,
@@ -6746,18 +6747,6 @@ func (s) TestAuthorityHeader(t *testing.T) {
67466747 },
67476748 wantAuthority : "localhost" ,
67486749 },
6749- {
6750- name : "Missing :authority and host" ,
6751- // Codepath triggered by incoming headers with no :authority and no
6752- // host.
6753- headers : []string {
6754- ":method" , "POST" ,
6755- ":path" , "/grpc.testing.TestService/UnaryCall" ,
6756- "content-type" , "application/grpc" ,
6757- "te" , "trailers" ,
6758- },
6759- wantAuthority : "" ,
6760- },
67616750 // "If :authority is present, Host must be discarded." - A41
67626751 {
67636752 name : ":authority and host present" ,
@@ -6820,6 +6809,73 @@ func (s) TestAuthorityHeader(t *testing.T) {
68206809 }
68216810}
68226811
6812+ // TestMissingAuthorityAndHostHeader tests that an incoming HTTP/2 request with
6813+ // neither :authority nor host header is rejected with HTTP status 400 and gRPC
6814+ // status Internal.
6815+ func (s ) TestMissingAuthorityAndHostHeader (t * testing.T ) {
6816+ lis , err := net .Listen ("tcp" , "localhost:0" )
6817+ if err != nil {
6818+ t .Fatalf ("Failed to listen: %v" , err )
6819+ }
6820+ defer lis .Close ()
6821+ s := grpc .NewServer ()
6822+ defer s .Stop ()
6823+ go s .Serve (lis )
6824+
6825+ conn , err := net .DialTimeout ("tcp" , lis .Addr ().String (), defaultTestTimeout )
6826+ if err != nil {
6827+ t .Fatalf ("Failed to dial server: %v" , err )
6828+ }
6829+ defer conn .Close ()
6830+
6831+ st := newServerTesterFromConn (t , conn )
6832+ st .greet ()
6833+
6834+ st .writeHeaders (http2.HeadersFrameParam {
6835+ StreamID : 1 ,
6836+ BlockFragment : st .encodeHeader (
6837+ ":method" , "POST" ,
6838+ ":path" , "/grpc.testing.TestService/UnaryCall" ,
6839+ "content-type" , "application/grpc" ,
6840+ "te" , "trailers" ,
6841+ ),
6842+ EndStream : false ,
6843+ EndHeaders : true ,
6844+ })
6845+
6846+ for {
6847+ frame , err := st .readFrame ()
6848+ if err != nil {
6849+ t .Fatalf ("Error reading frame: %v" , err )
6850+ }
6851+ hf , ok := frame .(* http2.MetaHeadersFrame )
6852+ if ! ok {
6853+ continue
6854+ }
6855+ var httpStatus , grpcStatus , grpcMessage string
6856+ for _ , h := range hf .Fields {
6857+ switch h .Name {
6858+ case ":status" :
6859+ httpStatus = h .Value
6860+ case "grpc-status" :
6861+ grpcStatus = h .Value
6862+ case "grpc-message" :
6863+ grpcMessage = h .Value
6864+ }
6865+ }
6866+ if httpStatus != "400" {
6867+ t .Fatalf ("Got HTTP status %v, want 400" , httpStatus )
6868+ }
6869+ if grpcStatus != "13" {
6870+ t .Fatalf ("Got gRPC status %v, want 13 (Internal)" , grpcStatus )
6871+ }
6872+ if ! strings .Contains (grpcMessage , "no host or :authority header present" ) {
6873+ t .Fatalf ("Got gRPC message %q, want 'no host or :authority header present'" , grpcMessage )
6874+ }
6875+ return
6876+ }
6877+ }
6878+
68236879func (s ) TestHTTPServerSendsNonGRPCHeaderSurfaceFurtherData (t * testing.T ) {
68246880 const htmlPayload = `<html><body>Hello World</body></html>`
68256881 const nonGRPCDataMaxLen = 1024
0 commit comments