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