@@ -477,6 +477,16 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
477
477
req .Header .Set ("Upgrade" , "DERP" )
478
478
req .Header .Set ("Connection" , "Upgrade" )
479
479
480
+ regionID := 0
481
+ if reg != nil {
482
+ regionID = reg .RegionID
483
+ }
484
+ if tlsState != nil && tlsState .NegotiatedProtocol == "h2" {
485
+ reason := "The server wanted us to use HTTP/2, but DERP requires Upgrade which needs HTTP/1.1"
486
+ c .forceWebsockets (regionID , reason )
487
+ return nil , 0 , fmt .Errorf ("DERP server did not switch protocols: %s" , reason )
488
+ }
489
+
480
490
if ! serverPub .IsZero () && serverProtoVersion != 0 {
481
491
// parseMetaCert found the server's public key (no TLS
482
492
// middlebox was in the way), so skip the HTTP upgrade
@@ -492,17 +502,6 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
492
502
// No need to flush the HTTP request. the derp.Client's initial
493
503
// client auth frame will flush it.
494
504
} else {
495
- regionID := 0
496
- if reg != nil {
497
- regionID = reg .RegionID
498
- }
499
-
500
- if tlsState != nil && tlsState .NegotiatedProtocol == "h2" {
501
- reason := fmt .Sprintf ("The server wanted us to use HTTP/2, but DERP requires Upgrade which needs HTTP/1.1" )
502
- c .forceWebsockets (regionID , reason )
503
- return nil , 0 , fmt .Errorf ("DERP server did not switch protocols: %s" , reason )
504
- }
505
-
506
505
if err := req .Write (brw ); err != nil {
507
506
return nil , 0 , err
508
507
}
@@ -650,7 +649,7 @@ func (c *Client) tlsConfig(node *tailcfg.DERPNode) *tls.Config {
650
649
tlsdial .SetConfigExpectedCert (tlsConf , node .CertName )
651
650
}
652
651
}
653
- tlsConf .NextProtos = []string {"h2" , " http/1.1" }
652
+ tlsConf .NextProtos = []string {"http/1.1" , "h2 " }
654
653
return tlsConf
655
654
}
656
655
0 commit comments