@@ -71,7 +71,7 @@ func (p *Server) Start(ctx context.Context) error {
71
71
if err != nil {
72
72
select {
73
73
case <- ctx .Done ():
74
- listener .Close ()
74
+ _ = listener .Close ()
75
75
return
76
76
default :
77
77
p .logger .Error ("Failed to accept connection" , "error" , err )
@@ -194,7 +194,7 @@ func (p *Server) forwardRequest(w http.ResponseWriter, r *http.Request, https bo
194
194
http .Error (w , fmt .Sprintf ("Failed to make request: %v" , err ), http .StatusBadGateway )
195
195
return
196
196
}
197
- defer resp .Body .Close ()
197
+ defer func () { _ = resp .Body .Close () } ()
198
198
199
199
p .logger .Debug ("Received response" , "status" , resp .StatusCode , "target" , targetURL .String ())
200
200
@@ -238,7 +238,7 @@ func (p *Server) writeBlockedResponse(w http.ResponseWriter, r *http.Request) {
238
238
host = r .Host
239
239
}
240
240
241
- fmt .Fprintf (w , `🚫 Request Blocked by Boundary
241
+ _ , _ = fmt .Fprintf (w , `🚫 Request Blocked by Boundary
242
242
243
243
Request: %s %s
244
244
Host: %s
@@ -290,7 +290,7 @@ func (p *Server) handleConnect(w http.ResponseWriter, r *http.Request) {
290
290
p .logger .Error ("Failed to hijack connection" , "error" , err )
291
291
return
292
292
}
293
- defer conn .Close ()
293
+ defer func () { _ = conn .Close () } ()
294
294
295
295
// Send 200 Connection established response manually
296
296
_ , err = conn .Write ([]byte ("HTTP/1.1 200 Connection established\r \n \r \n " ))
@@ -416,7 +416,7 @@ func (p *Server) handleDecryptedHTTPS(w http.ResponseWriter, r *http.Request) {
416
416
417
417
// handleConnectionWithTLSDetection detects TLS vs HTTP and handles appropriately
418
418
func (p * Server ) handleConnectionWithTLSDetection (conn net.Conn ) {
419
- defer conn .Close ()
419
+ defer func () { _ = conn .Close () } ()
420
420
421
421
// Peek at first byte to detect protocol
422
422
buf := make ([]byte , 1 )
@@ -442,15 +442,15 @@ func (p *Server) handleConnectionWithTLSDetection(conn net.Conn) {
442
442
p .logger .Debug ("TLS handshake successful" )
443
443
// Use HTTP server with TLS connection
444
444
listener := newSingleConnectionListener (tlsConn )
445
- defer listener .Close ()
445
+ defer func () { _ = listener .Close () } ()
446
446
err = http .Serve (listener , http .HandlerFunc (p .handleDecryptedHTTPS ))
447
447
p .logger .Debug ("http.Serve completed for HTTPS" , "error" , err )
448
448
} else {
449
449
p .logger .Debug ("Detected HTTP request, handling normally" )
450
450
// Use HTTP server with regular connection
451
451
p .logger .Debug ("About to call http.Serve for HTTP connection" )
452
452
listener := newSingleConnectionListener (connWrapper )
453
- defer listener .Close ()
453
+ defer func () { _ = listener .Close () } ()
454
454
err = http .Serve (listener , http .HandlerFunc (p .handleHTTP ))
455
455
p .logger .Debug ("http.Serve completed" , "error" , err )
456
456
}
@@ -519,7 +519,7 @@ func (sl *singleConnectionListener) Close() error {
519
519
}
520
520
521
521
if sl .conn != nil {
522
- sl .conn .Close ()
522
+ _ = sl .conn .Close ()
523
523
sl .conn = nil
524
524
}
525
525
return nil
@@ -613,9 +613,9 @@ func (p *Server) constructFullURL(req *http.Request, hostname string) string {
613
613
614
614
// writeBlockedResponseStreaming writes a blocked response directly to the TLS connection
615
615
func (p * Server ) writeBlockedResponseStreaming (tlsConn * tls.Conn , req * http.Request ) {
616
- response := fmt .Sprintf ("HTTP/1.1 403 Forbidden\r \n Content-Type: text/plain\r \n Connection: close\r \n \r \n 🚫 Request Blocked by Boundary\n \n Request: %s %s\n Host: %s\n \n To allow this request, restart boundary with:\n --allow \" %s\" \n " ,
616
+ response := fmt .Sprintf ("HTTP/1.1 403 Forbidden\r \n Content-Type: text/plain\r \n Connection: close\r \n \r \n 🚫 Request Blocked by Boundary\n \n Request: %s %s\n Host: %s\n \n To allow this request, restart boundary with:\n --allow \" %s\" \n " ,
617
617
req .Method , req .URL .Path , req .Host , req .Host )
618
- tlsConn .Write ([]byte (response ))
618
+ _ , _ = tlsConn .Write ([]byte (response ))
619
619
}
620
620
621
621
// streamRequestToTarget streams the HTTP request (including body) to the target server
@@ -625,29 +625,29 @@ func (p *Server) streamRequestToTarget(clientConn *tls.Conn, bufReader *bufio.Re
625
625
if err != nil {
626
626
return fmt .Errorf ("failed to connect to target %s: %v" , hostname , err )
627
627
}
628
- defer targetConn .Close ()
628
+ defer func () { _ = targetConn .Close () } ()
629
629
630
630
// Send HTTP request headers to target
631
631
reqLine := fmt .Sprintf ("%s %s %s\r \n " , req .Method , req .URL .RequestURI (), req .Proto )
632
- targetConn .Write ([]byte (reqLine ))
632
+ _ , _ = targetConn .Write ([]byte (reqLine ))
633
633
634
634
// Send headers
635
635
for name , values := range req .Header {
636
636
for _ , value := range values {
637
637
headerLine := fmt .Sprintf ("%s: %s\r \n " , name , value )
638
- targetConn .Write ([]byte (headerLine ))
638
+ _ , _ = targetConn .Write ([]byte (headerLine ))
639
639
}
640
640
}
641
- targetConn .Write ([]byte ("\r \n " )) // End of headers
641
+ _ , _ = targetConn .Write ([]byte ("\r \n " )) // End of headers
642
642
643
643
// Stream request body and response bidirectionally
644
644
go func () {
645
645
// Stream request body: client -> target
646
- io .Copy (targetConn , bufReader )
646
+ _ , _ = io .Copy (targetConn , bufReader )
647
647
}()
648
648
649
649
// Stream response: target -> client
650
- io .Copy (clientConn , targetConn )
650
+ _ , _ = io .Copy (clientConn , targetConn )
651
651
return nil
652
652
}
653
653
@@ -661,7 +661,7 @@ func (p *Server) handleConnectStreaming(tlsConn *tls.Conn, req *http.Request, ho
661
661
662
662
// Send CONNECT response
663
663
response := "HTTP/1.1 200 Connection established\r \n \r \n "
664
- tlsConn .Write ([]byte (response ))
664
+ _ , _ = tlsConn .Write ([]byte (response ))
665
665
666
666
// Now the client will try to do TLS handshake for the target server
667
667
// But we want to intercept and terminate it
@@ -676,9 +676,9 @@ func (p *Server) handleConnectStreaming(tlsConn *tls.Conn, req *http.Request, ho
676
676
p .logger .Error ("Failed to connect to CONNECT target" , "target" , req .Host , "error" , err )
677
677
return
678
678
}
679
- defer targetConn .Close ()
680
-
679
+ defer func () { _ = targetConn .Close () } ()
680
+
681
681
// Bidirectional copy
682
- go io .Copy (targetConn , tlsConn )
683
- io .Copy (tlsConn , targetConn )
682
+ go func () { _ , _ = io .Copy (targetConn , tlsConn ) }( )
683
+ _ , _ = io .Copy (tlsConn , targetConn )
684
684
}
0 commit comments