>_ IzzyLab

Hands-on task

This task is step 11 of the course “curl and HTTP APIs”

Where does the link end up

medium~7 min

A local service at http://127.0.0.1:8600/a responds with a redirect, and not just one. Find out how many redirects there were and at which final URL the request stopped, and write this as a single line of the form <number> <final URL> to /root/chain.txt.

What you'll practise:
  • curl -L
  • redirects
  • -w output variables
  • num_redirects
  • url_effective

Topic breakdown

3xx codes return the address of the next step in the Location header; the client decides whether to follow it. curl without -L stops at the first such response, with -L it follows the chain (limited by --max-redirs). The -w flag prints the values of internal variables after the request completes: besides num_redirects and url_effective there are http_code, time_total, size_download and others. This removes the need to parse headers with external tools and makes such checks suitable for scripts and monitoring.

What's checked

  1. number of redirects and final URL are correct
  2. the file has exactly one line

What it looks like