Initial commit

This commit is contained in:
2026-05-26 16:32:55 +03:00
commit 4f2d899130
427 changed files with 231313 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
package deconnector
import (
"bufio"
"fmt"
"net"
"net/http"
"net/url"
)
func (d *Deconnector) forwardHTTP(clientConn net.Conn, req *http.Request, upstreamURL *url.URL) {
upstreamConn, err := d.dialer.Dial()
if err != nil {
d.app.Logger().WithError(err).Error("upstream dial failed")
fmt.Fprintf(clientConn, "HTTP/1.1 502 Bad Gateway\r\n\r\n")
return
}
defer upstreamConn.Close()
if err := req.WriteProxy(upstreamConn); err != nil {
d.app.Logger().WithError(err).Error("failed to write request")
return
}
resp, err := http.ReadResponse(bufio.NewReader(upstreamConn), req)
if err != nil {
d.app.Logger().WithError(err).Error("failed to read response")
return
}
defer resp.Body.Close()
resp.Write(clientConn)
}