Skip to content

Commit e3aa2cb

Browse files
blink-so[bot]f0ssel
andcommitted
Add comprehensive debug logging to forwardHTTPRequest
- Add logging for URL construction and target resolution - Log HTTP client request creation and execution - Track response reception and body copying - Helps diagnose 'Empty reply from server' issue in privileged mode - No functional changes, only improved observability Co-authored-by: f0ssel <[email protected]>
1 parent 1c08958 commit e3aa2cb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

proxy/proxy.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ func (p *Server) handleHTTPS(w http.ResponseWriter, r *http.Request) {
183183

184184
// forwardHTTPRequest forwards a regular HTTP request
185185
func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
186+
p.logger.Debug("forwardHTTPRequest called", "method", r.Method, "url", r.URL.String(), "host", r.Host)
187+
186188
// Create a new request to the target server
187189
targetURL := r.URL
188190
if targetURL.Scheme == "" {
@@ -192,6 +194,8 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
192194
targetURL.Host = r.Host
193195
}
194196

197+
p.logger.Debug("Target URL constructed", "target", targetURL.String())
198+
195199
// Create HTTP client
196200
client := &http.Client{
197201
CheckRedirect: func(req *http.Request, via []*http.Request) error {
@@ -202,6 +206,7 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
202206
// Create new request
203207
req, err := http.NewRequest(r.Method, targetURL.String(), r.Body)
204208
if err != nil {
209+
p.logger.Error("Failed to create forward request", "error", err)
205210
http.Error(w, fmt.Sprintf("Failed to create request: %v", err), http.StatusInternalServerError)
206211
return
207212
}
@@ -213,14 +218,19 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
213218
}
214219
}
215220

221+
p.logger.Debug("About to make HTTP request", "target", targetURL.String())
222+
216223
// Make the request
217224
resp, err := client.Do(req)
218225
if err != nil {
226+
p.logger.Error("Failed to make forward request", "error", err)
219227
http.Error(w, fmt.Sprintf("Failed to make request: %v", err), http.StatusBadGateway)
220228
return
221229
}
222230
defer resp.Body.Close()
223231

232+
p.logger.Debug("Received response", "status", resp.StatusCode, "target", targetURL.String())
233+
224234
// Copy response headers
225235
for name, values := range resp.Header {
226236
for _, value := range values {
@@ -232,7 +242,12 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
232242
w.WriteHeader(resp.StatusCode)
233243

234244
// Copy response body
235-
io.Copy(w, resp.Body)
245+
_, copyErr := io.Copy(w, resp.Body)
246+
if copyErr != nil {
247+
p.logger.Debug("Error copying response body", "error", copyErr)
248+
} else {
249+
p.logger.Debug("Successfully forwarded HTTP response")
250+
}
236251
}
237252

238253
// forwardHTTPSRequest forwards an HTTPS request

0 commit comments

Comments
 (0)