@@ -1645,6 +1645,53 @@ func testTLSServer(t *testing.T, mode testMode) {
1645
1645
}
1646
1646
}
1647
1647
1648
+ type fakeConnectionStateConn struct {
1649
+ net.Conn
1650
+ }
1651
+
1652
+ func (fcsc * fakeConnectionStateConn ) ConnectionState () tls.ConnectionState {
1653
+ return tls.ConnectionState {
1654
+ ServerName : "example.com" ,
1655
+ }
1656
+ }
1657
+
1658
+ func TestTLSServerWithoutTLSConn (t * testing.T ) {
1659
+ //set up
1660
+ pr , pw := net .Pipe ()
1661
+ c := make (chan int )
1662
+ listener := & oneConnListener {& fakeConnectionStateConn {pr }}
1663
+ server := & Server {
1664
+ Handler : HandlerFunc (func (writer ResponseWriter , request * Request ) {
1665
+ if request .TLS == nil {
1666
+ t .Fatal ("request.TLS is nil, expected not nil" )
1667
+ }
1668
+ if request .TLS .ServerName != "example.com" {
1669
+ t .Fatalf ("request.TLS.ServerName is %s, expected %s" , request .TLS .ServerName , "example.com" )
1670
+ }
1671
+ writer .Header ().Set ("X-TLS-ServerName" , "example.com" )
1672
+ }),
1673
+ }
1674
+
1675
+ // write request and read response
1676
+ go func () {
1677
+ req , _ := NewRequest (MethodGet , "https://example.com" , nil )
1678
+ req .Write (pw )
1679
+
1680
+ resp , _ := ReadResponse (bufio .NewReader (pw ), req )
1681
+ if hdr := resp .Header .Get ("X-TLS-ServerName" ); hdr != "example.com" {
1682
+ t .Errorf ("response header X-TLS-ServerName is %s, expected %s" , hdr , "example.com" )
1683
+ }
1684
+ close (c )
1685
+ pw .Close ()
1686
+ }()
1687
+
1688
+ server .Serve (listener )
1689
+
1690
+ // oneConnListener returns error after one accept, wait util response is read
1691
+ <- c
1692
+ pr .Close ()
1693
+ }
1694
+
1648
1695
func TestServeTLS (t * testing.T ) {
1649
1696
CondSkipHTTP2 (t )
1650
1697
// Not parallel: uses global test hooks.
0 commit comments