pgs-lite.diff

· erock's pastes · raw

expires: 2025-09-07

 1diff --git a/cmd/pgs/lite/main.go b/cmd/pgs/lite/main.go
 2index 57bbf60..ff8ce0e 100644
 3--- a/cmd/pgs/lite/main.go
 4+++ b/cmd/pgs/lite/main.go
 5@@ -3,6 +3,7 @@ package main
 6 import (
 7 	"context"
 8 	"fmt"
 9+	"net"
10 	"net/http"
11 	"net/http/httputil"
12 
13@@ -17,19 +18,16 @@ type cachedHttp struct {
14 }
15 
16 func (c *cachedHttp) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
17-	logger := c.routes.Cfg.Logger
18 	_ = c.handler.ServeHTTP(writer, req, func(w http.ResponseWriter, r *http.Request) error {
19-		// TODO: how to i pass this request to `ash.pgs.sh`?
20-		destUrl := r.URL
21-		logger.Info("proxy request", "url", destUrl.String())
22-
23-		proxy := httputil.NewSingleHostReverseProxy(destUrl)
24-		oldDirector := proxy.Director
25-		proxy.Director = func(r *http.Request) {
26-			oldDirector(r)
27-			r.Host = destUrl.Host
28-			r.URL = destUrl
29+		defaultTransport := http.DefaultTransport.(*http.Transport)
30+		newTransport := defaultTransport.Clone()
31+		oldDialContext := newTransport.DialContext
32+		newTransport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
33+			return oldDialContext(ctx, "tcp", "ash.pgs.sh:443")
34 		}
35+		proxy := httputil.NewSingleHostReverseProxy(r.URL)
36+		proxy.Transport = newTransport
37+
38 		proxy.ServeHTTP(w, r)
39 		return nil
40 	})