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:

  1. 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 connect selects HTTP CONNECT and -x takes the proxy's address. The Host header includes the test URL's port when the URL specifies one. printf supplies HTTP line endings and the blank line after the headers. timeout 10s limits the run, including the proxy handshake.

  2. 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.txt on the sample server, the status is 200 OK and the body contains Service ready. An nc: Proxy error message means the tunnel request failed. An empty reply or an unexpected status or body leaves the expected result unverified.

Share this guide