@@ -372,6 +372,132 @@ func TestServerInvalidHeader(t *testing.T) {
372372 })
373373}
374374
375+ func TestServerAuthorityAndHostHeader (t * testing.T ) {
376+ for _ , test := range []struct {
377+ name string
378+ h http.Header
379+ valid bool
380+ wantHost string
381+ }{{
382+ name : "authority host mismatch" ,
383+ h : http.Header {
384+ ":authority" : {"example.tld" },
385+ "host" : {"other.tld" },
386+ },
387+ }, {
388+ // The RFCs aren't explicit on whether a :authority and host that
389+ // differ only in case is a mismatch. We treat it as a mismatch because
390+ // there doesn't seem to be a good reason not to.
391+ name : "authority host case differs" ,
392+ h : http.Header {
393+ ":authority" : {"example.tld" },
394+ "host" : {"EXAMPLE.TLD" },
395+ },
396+ }, {
397+ name : "authority and multiple host" ,
398+ h : http.Header {
399+ ":authority" : {"example.tld" },
400+ "host" : {"example.tld" , "example.tld" },
401+ },
402+ }, {
403+ name : "multiple host only" ,
404+ h : http.Header {
405+ "host" : {"example.tld" , "example.tld" },
406+ },
407+ }, {
408+ name : "multiple authority only" ,
409+ h : http.Header {
410+ ":authority" : {"example.tld" , "example.tld" },
411+ },
412+ }, {
413+ name : "empty authority" ,
414+ h : http.Header {
415+ ":authority" : {"" },
416+ },
417+ }, {
418+ name : "invalid authority" ,
419+ h : http.Header {
420+ ":authority" : {"example . tld" },
421+ },
422+ }, {
423+ name : "invalid host" ,
424+ h : http.Header {
425+ "host" : {"example . tld" },
426+ },
427+ }, {
428+ name : "authority only" ,
429+ h : http.Header {
430+ ":authority" : {"example.tld" },
431+ },
432+ valid : true ,
433+ wantHost : "example.tld" ,
434+ }, {
435+ name : "host only" ,
436+ h : http.Header {
437+ "host" : {"example.tld" },
438+ },
439+ valid : true ,
440+ wantHost : "example.tld" ,
441+ }, {
442+ name : "authority host match" ,
443+ h : http.Header {
444+ ":authority" : {"example.tld" },
445+ "host" : {"example.tld" },
446+ },
447+ valid : true ,
448+ wantHost : "example.tld" ,
449+ }, {
450+ name : "authority host match with port" ,
451+ h : http.Header {
452+ ":authority" : {"example.tld:443" },
453+ "host" : {"example.tld:443" },
454+ },
455+ valid : true ,
456+ wantHost : "example.tld:443" ,
457+ }, {
458+ name : "authority host mismatch with port" ,
459+ h : http.Header {
460+ ":authority" : {"example.tld:80" },
461+ "host" : {"example.tld:443" },
462+ },
463+ }, {
464+ name : "userinfo in authority" ,
465+ h : http.Header {
466+ ":authority" : {
"user:[email protected] " },
467+ },
468+ }, {
469+ name : "userinfo in host" ,
470+ h : http.Header {
471+ "host" : {
"user:[email protected] " },
472+ },
473+ }, {
474+ name : "neither authority nor host" ,
475+ h : http.Header {},
476+ valid : true ,
477+ wantHost : "" ,
478+ }} {
479+ synctestSubtest (t , test .name , func (t * testing.T ) {
480+ ts := newTestServer (t , nil )
481+ tc := ts .connect ()
482+ tc .greet ()
483+
484+ reqStream := tc .newStream (streamTypeRequest )
485+ reqStream .writeHeaders (requestHeader (test .h ))
486+ if test .valid {
487+ call := tc .nextHandlerCall ()
488+ if call == nil {
489+ t .Fatal ("no server handler call; want one" )
490+ }
491+ if got , want := call .req .Host , test .wantHost ; got != want {
492+ t .Errorf ("handler got Host %q, want %q" , got , want )
493+ }
494+ } else {
495+ reqStream .wantError (quic .StreamErrorCode (errH3MessageError ))
496+ }
497+ })
498+ }
499+ }
500+
375501func TestServerInvalidStatus (t * testing.T ) {
376502 synctest .Test (t , func (t * testing.T ) {
377503 gotpanic := make (chan bool )
0 commit comments