Fix linter issues

This commit is contained in:
2026-05-27 10:58:13 +03:00
parent 11a357ebc4
commit 024d5fd96c
13 changed files with 145 additions and 46 deletions

View File

@@ -2,14 +2,14 @@ package deconnector
import (
"bufio"
"context"
"fmt"
"net"
"net/http"
"net/url"
)
func (d *Deconnector) forwardHTTP(clientConn net.Conn, req *http.Request, upstreamURL *url.URL) {
upstreamConn, err := d.dialer.Dial()
func (d *Deconnector) forwardHTTP(ctx context.Context, clientConn net.Conn, req *http.Request) {
upstreamConn, err := d.dialer.Dial(ctx)
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")
@@ -18,6 +18,10 @@ func (d *Deconnector) forwardHTTP(clientConn net.Conn, req *http.Request, upstre
}
defer upstreamConn.Close()
if authHeader, ok := d.dialer.Auth(); ok {
req.Header.Set("Proxy-Authorization", "Basic "+authHeader)
}
if err := req.WriteProxy(upstreamConn); err != nil {
d.app.Logger().WithError(err).Error("failed to write request")
@@ -33,5 +37,8 @@ func (d *Deconnector) forwardHTTP(clientConn net.Conn, req *http.Request, upstre
defer resp.Body.Close()
resp.Write(clientConn)
err = resp.Write(clientConn)
if err != nil {
d.app.Logger().WithError(err).Error("failed to write response")
}
}