Skip to content

Commit

Permalink
ProxyHttpServer.Tr.Dial() Deprecated, use DialContext() instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
youngifif authored and elazarl committed Dec 11, 2024
1 parent 60626ae commit 3df585c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions examples/goproxy-sokeepalive/sokeepalive.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"flag"
"github.com/elazarl/goproxy"
"log"
Expand All @@ -13,10 +14,19 @@ func main() {
addr := flag.String("addr", ":8080", "proxy listen address")
flag.Parse()
proxy := goproxy.NewProxyHttpServer()
proxy.Tr.Dial = func(network, addr string) (c net.Conn, err error) {
c, err = net.Dial(network, addr)
proxy.Tr.DialContext = func(ctx context.Context, network, addr string) (c net.Conn, err error) {
var d net.Dialer
c, err = d.DialContext(ctx, network, addr)
if c, ok := c.(*net.TCPConn); err == nil && ok {
c.SetKeepAlive(true)
go func() {
select {
case <-ctx.Done():
{
c.Close()
}
}
}()
}
return
}
Expand Down

0 comments on commit 3df585c

Please sign in to comment.