cache dns maybe

This commit is contained in:
bel
2026-07-15 21:02:41 -06:00
parent f1b4b88091
commit e4acfff5a2
4 changed files with 21 additions and 0 deletions
+2
View File
@@ -3,3 +3,5 @@ module rproxy4
go 1.24.2
require gopkg.in/yaml.v2 v2.4.0
require github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8 // indirect
+2
View File
@@ -1,3 +1,5 @@
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8 h1:EVObHAr8DqpoJCVv6KYTle8FEImKhtkfcZetNqxDoJQ=
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+17
View File
@@ -1,13 +1,18 @@
package main
import (
"context"
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
"strings"
"time"
"github.com/viki-org/dnscache"
)
func main() {
@@ -32,6 +37,8 @@ func main() {
}
}
var resolver = dnscache.New(time.Minute * 500)
func (c Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
endpoint := c.endpoint(r)
if endpoint.To == "" {
@@ -71,8 +78,18 @@ func (c Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Printf("[%s] %v", c.key(r), err)
}
var transport http.Transport
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
if ip, _ := resolver.FetchOneString(strings.Split(u.Host, ":")[0]); ip != "" {
transport.DialContext = func(ctx context.Context, network string, address string) (net.Conn, error) {
if idx := strings.LastIndex(u.Host, ":"); idx > 0 {
ip = ip + u.Host[idx:]
}
return (&net.Dialer{}).DialContext(ctx, network, ip)
}
}
proxy := httputil.NewSingleHostReverseProxy(u)
proxy.Transport = redirPurge{
proxyHost: r.Host,
Executable
BIN
View File
Binary file not shown.