Skip to content

Commit c57c947

Browse files
test: add http connect tests for proxy package
1 parent 47dc0af commit c57c947

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

proxy/proxy_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,40 @@ func TestProxyServerCONNECT(t *testing.T) {
293293
require.Equal(t, expectedResponse, string(body))
294294
})
295295

296+
// Test HTTP request through proxy transport
297+
t.Run("HTTPRequestThroughProxyTransport", func(t *testing.T) {
298+
// Create proxy URL
299+
proxyURL, err := url.Parse("http://localhost:8080")
300+
require.NoError(t, err)
301+
302+
// Create HTTP client with proxy transport
303+
client := &http.Client{
304+
Transport: &http.Transport{
305+
Proxy: http.ProxyURL(proxyURL),
306+
},
307+
Timeout: 10 * time.Second,
308+
}
309+
310+
// For HTTP requests, Go will send the request directly to the proxy
311+
// The proxy will forward it to the target server
312+
resp, err := client.Get("http://jsonplaceholder.typicode.com/todos/1")
313+
require.NoError(t, err)
314+
defer resp.Body.Close()
315+
316+
// Read response
317+
body, err := io.ReadAll(resp.Body)
318+
require.NoError(t, err)
319+
320+
// Verify response contains expected content
321+
expectedResponse := `{
322+
"userId": 1,
323+
"id": 1,
324+
"title": "delectus aut autem",
325+
"completed": false
326+
}`
327+
require.Equal(t, expectedResponse, string(body))
328+
})
329+
296330
err = server.Stop()
297331
require.NoError(t, err)
298332
}

0 commit comments

Comments
 (0)