if no dig then no hijack

master
Bel LaPointe 2022-12-26 14:02:21 -05:00
parent 9a60d782e3
commit e5ba5c9777
1 changed files with 10 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"log"
"net"
"net/http"
"net/http/httputil"
"strings"
"time"
@ -78,6 +79,11 @@ func (s *Server) Connect(w http.ResponseWriter, r *http.Request) {
return
}
if host == r.Host {
s.connectHTTPReverseProxy(w, r)
return
}
dest, err := net.DialTimeout("tcp", host, s.Timeout)
if err != nil {
s.Error(r, w, fmt.Errorf("error dialing w timeout %s=>%s: %w", r.Host, host, err))
@ -102,6 +108,10 @@ func (s *Server) Connect(w http.ResponseWriter, r *http.Request) {
go s.xfer(r.Context(), client, dest)
}
func (s *Server) connectHTTPReverseProxy(w http.ResponseWriter, r *http.Request) {
httputil.NewSingleHostReverseProxy(r.URL).ServeHTTP(w, r)
}
func (s *Server) Serve(w http.ResponseWriter, r *http.Request) {
resp, err := s.Transport.RoundTrip(r)
if err != nil {