@@ -186,19 +186,18 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
186
186
p .logger .Debug ("forwardHTTPRequest called" , "method" , r .Method , "url" , r .URL .String (), "host" , r .Host )
187
187
188
188
// Create a new request to the target server
189
- targetURL := r .URL
190
- if targetURL .Scheme == "" {
191
- targetURL .Scheme = "http"
192
- }
193
- if targetURL .Host == "" {
194
- targetURL .Host = r .Host
189
+ targetURL := & url.URL {
190
+ Scheme : "http" ,
191
+ Host : r .Host ,
192
+ Path : r .URL .Path ,
193
+ RawQuery : r .URL .RawQuery ,
195
194
}
196
195
197
196
p .logger .Debug ("Target URL constructed" , "target" , targetURL .String ())
198
197
199
- // Create HTTP client
198
+ // Create HTTP client with shorter timeout
200
199
client := & http.Client {
201
- Timeout : 10 * time .Second , // Add timeout to avoid hanging
200
+ Timeout : 5 * time .Second ,
202
201
CheckRedirect : func (req * http.Request , via []* http.Request ) error {
203
202
return http .ErrUseLastResponse // Don't follow redirects
204
203
},
@@ -214,15 +213,19 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
214
213
215
214
// Copy headers
216
215
for name , values := range r .Header {
216
+ // Skip connection-specific headers
217
+ if strings .ToLower (name ) == "connection" || strings .ToLower (name ) == "proxy-connection" {
218
+ continue
219
+ }
217
220
for _ , value := range values {
218
221
req .Header .Add (name , value )
219
222
}
220
223
}
221
224
222
225
p .logger .Debug ("About to make HTTP request" , "target" , targetURL .String ())
223
226
224
- // Make the request
225
- ctx , cancel := context .WithTimeout (context . Background (), 10 * time .Second )
227
+ // Make the request with context
228
+ ctx , cancel := context .WithTimeout (r . Context (), 5 * time .Second )
226
229
defer cancel ()
227
230
req = req .WithContext (ctx )
228
231
@@ -236,8 +239,11 @@ func (p *Server) forwardHTTPRequest(w http.ResponseWriter, r *http.Request) {
236
239
237
240
p .logger .Debug ("Received response" , "status" , resp .StatusCode , "target" , targetURL .String ())
238
241
239
- // Copy response headers
242
+ // Copy response headers (except connection-specific ones)
240
243
for name , values := range resp .Header {
244
+ if strings .ToLower (name ) == "connection" || strings .ToLower (name ) == "transfer-encoding" {
245
+ continue
246
+ }
241
247
for _ , value := range values {
242
248
w .Header ().Add (name , value )
243
249
}
0 commit comments