>_ IzzyLab

Hands-on task

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

Headers only: Content-Type

medium~7 min

Request only the headers of the response (no body) from http://localhost:8080/data and write the value of the Content-Type header to /root/ctype.txt.

What you'll practise:
  • curl
  • -I
  • HEAD
  • Content-Type
  • response headers

Topic breakdown

The HTTP HEAD method requests the same headers as GET, but without the body — useful for finding out a resource's type, size or availability without downloading it. In curl this is the -I (--head) option. Response headers are text of the form Name: value, separated by CRLF (\r\n), so when parsing them the trailing \r is usually stripped (tr -d '\r'). Content-Type gives the MIME type of the body (application/json, text/html), which lets the client know how to interpret it.

What's checked

  1. Content-Type extracted
  2. headers requested with a HEAD request

What it looks like