1515package smart
1616
1717import (
18+ "bufio"
1819 "bytes"
1920 "context"
2021 "crypto/tls"
@@ -23,6 +24,7 @@ import (
2324 "fmt"
2425 "io"
2526 "net"
27+ "net/http"
2628 "net/url"
2729 "sync"
2830 "time"
@@ -253,18 +255,45 @@ func (f *StrategyFinder) testDialer(ctx context.Context, dialer transport.Stream
253255 testCtx , cancel := context .WithTimeout (ctx , f .TestTimeout )
254256 defer cancel ()
255257
258+ // Dial
259+
256260 testConn , err := dialer .DialStream (testCtx , testAddr )
257261 if err != nil {
258262 f .logCtx (ctx , "🏁 failed to dial: '%v' (domain: %v), duration=%v, dial_error=%v ❌\n " , transportCfg , testDomain , time .Since (startTime ), err )
259263 return err
260264 }
265+
266+ // TLS Connection
267+
261268 tlsConn := tls .Client (testConn , & tls.Config {ServerName : testDomain })
269+ defer tlsConn .Close ()
262270 err = tlsConn .HandshakeContext (testCtx )
263- tlsConn .Close ()
264271 if err != nil {
265272 f .logCtx (ctx , "🏁 failed TLS handshake: '%v' (domain: %v), duration=%v, handshake=%v ❌\n " , transportCfg , testDomain , time .Since (startTime ), err )
266273 return err
267274 }
275+
276+ // HTTPS Get
277+
278+ req , err := http .NewRequestWithContext (testCtx , http .MethodHead , "https://" + testDomain , nil )
279+ if err != nil {
280+ return fmt .Errorf ("failed to create HTTP request: %w" , err )
281+ }
282+
283+ if err := req .Write (tlsConn ); err != nil {
284+ f .logCtx (ctx , "🏁 failed to write HTTP request: '%v' (domain: %v), duration=%v, error=%v ❌\n " , transportCfg , testDomain , time .Since (startTime ), err )
285+ return err
286+ }
287+
288+ resp , err := http .ReadResponse (bufio .NewReader (tlsConn ), req )
289+ if err != nil {
290+ f .logCtx (ctx , "🏁 failed to read HTTP response: '%v' (domain: %v), duration=%v, error=%v ❌\n " , transportCfg , testDomain , time .Since (startTime ), err )
291+ return err
292+ }
293+ defer resp .Body .Close ()
294+
295+ // Many bare domains return i.e. 301 redirects, so we don't validate anything about the response here, just that the request succeeded.
296+
268297 f .logCtx (ctx , "🏁 success: '%v' (domain: %v), duration=%v, status=ok ✅\n " , transportCfg , testDomain , time .Since (startTime ))
269298 }
270299 return nil
0 commit comments