A forward proxy can accept TCP connections while failing to relay data to the service you need. With OpenBSD Netcat on Ubuntu, you can test an HTTP proxy by sending a request through a tunnel and reading the destination's reply.
HTTP CONNECT asks the proxy to open a tunnel to a specific host and port. The proxy must already allow that destination and accept the tunnel request from your client without authentication.
A static health file with a known response gives you something to match in the reply. The request travels in plain text inside the tunnel, so choose a read-only HTTP endpoint that needs no credentials and returns no sensitive data.
Steps to test an HTTP proxy with Netcat:
- Send a GET request with your proxy host and port and your test URL's path, host, and port in place of the sample values.
printf '%s\r\n' 'GET /health.txt HTTP/1.1' \ 'Host: app.example.test:8080' 'Connection: close' '' | \ timeout 10s nc -X connect -x proxy.example.test:3128 \ app.example.test 8080
-X connectselects HTTP CONNECT and-xtakes the proxy's address. TheHostheader includes the test URL's port when the URL specifies one.printfsupplies HTTP line endings and the blank line after the headers.timeout 10slimits the run, including the proxy handshake.Tool: Netcat Command Generator
- Confirm that the output contains the expected HTTP status and body for your test URL.
HTTP/1.1 200 OK ##### snipped ##### Service ready
For
/health.txton the sample server, the status is200 OKand the body containsService ready. Annc: Proxy errormessage means the tunnel request failed. An empty reply or an unexpected status or body leaves the expected result unverified.