TT Lab
Get started
Learn Learning paths Courses

Network Troubleshooting

Diagnosing HTTP With curl

Continue in TT Lab

Goal

You pull status codes, headers, redirects, virtual hosts, and timing with curl, and practice turning "it's slow" and "it doesn't work" into segment names.

Why it matters

The timing fields of curl -w break one request into five segments: name resolution / TCP connect / TLS / first byte / total. With this breakdown, you can turn the report "the API is slow" into "the TLS handshake is 800ms", and at that moment the responsible team and the action are decided. --resolve and -H 'Host:' are essential tools for pre-deployment verification — you can test a new server by its real name before changing DNS, and while knocking directly on a backend behind an LB, you can still pass through virtual host routing as originally.

Steps

  1. Create the /root/http directory and start /opt/fixtures/nt-http/server.py on port 8088 in the background. It must still be alive at grading time.
  2. Request http://127.0.0.1:8088/ok in verbose mode and save the full output, including the request and response headers, to /root/http/verbose.txt.
  3. Write the status codes of the four paths /ok, /notfound, /teapot, and /redirect, one line each in the format 경로 코드 (path, then code), in /root/http/status.txt. (Do not follow the redirect)
  4. Save only the response headers of /ok to /root/http/headers.txt. The X-Labhub-Node header must be included.
  5. Request /chain following redirects, and write the final status code and the number of redirects on one line, code=<코드> redirects=<횟수> (code= followed by the code and redirects= followed by the count), in /root/http/redirect.txt.
  6. Request /whoami with the header Host: shop.labhub.local attached and save the response body to /root/http/host.txt.
  7. Use --resolve to make http://shop.labhub.local:8088/ok succeed without touching /etc/hosts, and save that response body to /root/http/resolve.txt.
  8. Make /root/http/timing.txt with the following 4 lines. The values are the actual measurements obtained by requesting the /slow path. code=<상태코드> / connect=<time_connect> / ttfb=<time_starttransfer> / total=<time_total> (each followed by the measured value) /slow has a 1.2-second delay, so total must be at least 1.

Notes

Starting the diagnostic server

Create the /root/http directory and start /opt/fixtures/nt-http/server.py on port 8088 in the background. It must still be alive at grading time.

The fixture server takes the port as an argument. After starting it, check the listening with ss.

Viewing the full request and response headers

Request http://127.0.0.1:8088/ok in verbose mode and save the full output, including the request and response headers, to /root/http/verbose.txt.

curl's verbose mode comes out on standard error. To keep it in a file, you need to use redirection as well.

Status code table per path

Write the status codes of the four paths /ok, /notfound, /teapot, and /redirect, one line each in the format 경로 코드 (path, then code), in /root/http/status.txt. (Do not follow the redirect)

You can pull out only the status code with an output format specifier. Discard the body and keep only the code.

Pulling out only the response headers

Save only the response headers of /ok to /root/http/headers.txt. The X-Labhub-Node header must be included.

If you combine the option that dumps the headers to standard output and the option that discards the body, you can see only the headers while keeping GET.

Following redirects

Request /chain following redirects, and write the final status code and the number of redirects on one line, code=<코드> redirects=<횟수> (code= followed by the code and redirects= followed by the count), in /root/http/redirect.txt.

There is an option that follows redirects, and an output variable that tells you how many times it followed.

Testing a virtual host with the Host header

Request /whoami with the header Host: shop.labhub.local attached and save the response body to /root/http/host.txt.

The fixture server's /whoami returns the Host header it received as it is.

Connecting by name without DNS

Use --resolve to make http://shop.labhub.local:8088/ok succeed without touching /etc/hosts, and save that response body to /root/http/resolve.txt.

--resolve takes the three values name:port:address joined by colons. You can do it without touching /etc/hosts.

Timing breakdown and report

Make /root/http/timing.txt with the following 4 lines. The values are the actual measurements obtained by requesting the /slow path. code=<상태코드> / connect=<time_connect> / ttfb=<time_starttransfer> / total=<time_total> (each followed by the measured value) /slow has a 1.2-second delay, so total must be at least 1.

The timing fields are cumulative values. The /slow path deliberately responds slowly.