1
0
mirror of https://github.com/fumiama/terasu-cloudflared.git synced 2026-06-28 08:00:26 +08:00

feat: embed terasu inside

This commit is contained in:
源文雨
2025-12-21 16:51:38 +08:00
parent 0d2a7a0385
commit f99b9330df
23 changed files with 1195 additions and 18 deletions

View File

@@ -31,6 +31,7 @@ import (
"sync/atomic"
"time"
"github.com/fumiama/terasu"
"golang.org/x/net/http/httpguts"
"golang.org/x/net/http2/hpack"
"golang.org/x/net/idna"
@@ -3275,13 +3276,22 @@ func traceGot1xxResponseFunc(trace *httptrace.ClientTrace) func(int, textproto.M
// dialTLSWithContext uses tls.Dialer, added in Go 1.15, to open a TLS
// connection.
func (t *Transport) dialTLSWithContext(ctx context.Context, network, addr string, cfg *tls.Config) (*tls.Conn, error) {
dialer := &tls.Dialer{
Config: cfg,
}
dialer := &net.Dialer{}
cn, err := dialer.DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
tlsCn := cn.(*tls.Conn) // DialContext comment promises this will always succeed
tlsCn := tls.Client(terasu.NewConn(cn), cfg)
if deadline, ok := ctx.Deadline(); ok {
cn.SetDeadline(deadline)
}
err = tlsCn.Handshake()
if _, ok := ctx.Deadline(); ok {
cn.SetDeadline(time.Time{})
}
if err != nil {
cn.Close()
return nil, err
}
return tlsCn, nil
}