>_ IzzyLab

Hands-on task

This task is step 5 of the course “Networking: first steps”

Which code the site returned

easy~5 min

The marketing team complains: the promo page http://localhost:8080/promo "won't open", while the home page http://localhost:8080/ works. The page text doesn't explain what's wrong. Find out which HTTP response code the server returns for the promo address and write it to /root/promo_code.txt — just the three-digit number.

What you'll practise:
  • curl -I
  • curl -w
  • HTTP response codes

Topic breakdown

A web server answers every request with a code — a three-digit number that briefly says how it went. The first digit is the class of the answer:

  • 2xx — all good (200 OK);
  • 3xx — a redirect: the page is at another address (301, 302);
  • 4xx — an error in the request: no such page (404), access denied (403);
  • 5xx — an error on the server's side (500, 502, 503).

The code arrives in the first line of the headers, before the page itself. A browser doesn't show it, but curl does with a flag:

$ curl -I http://example.local/docs
HTTP/1.1 301 Moved Permanently
Location: http://example.local/docs/
Content-Type: text/html

-I requests only the headers, without the page. If you need just the code — for a script, say — the -w flag (what to print after the request) comes in handy:

$ curl -s -o /dev/null -w '%{http_code}\n' http://example.local/docs
301

Here -s hides the progress meter, and -o /dev/null throws away the response body.

What's checked

  1. File /root/promo_code.txt created
  2. The file holds a single three-digit number
  3. It's the response code for the promo address

What it looks like