We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

What Are HTTP Headers?

An HTTP header allows clients and servers to pass additional information with each request or response. Headers are just case-insensitive key-value pairs that pass additional metadata about the request or response.

HTTP requests from a web browser automatically carry with them many headers, including but not limited to:

  • The type of client (e.g. Google Chrome)
  • The Operating system (e.g. Windows)
  • The preferred language (e.g. US English)

As developers, we can also define custom headers in each request.

Headers API

The Headers API allows us to perform various actions on our request and response headers such as retrieving, setting, and removing them. We can access the headers object through the Request.headers and Response.headers properties.

Assignment

Complete the getContentType() function. It takes a response object as input and should return the Content-Type.

Take a look at the test suite to see exactly how it's being created.

Use the .get() method on the response object's headers property to get access to the header you need.

The return type is string but .get() will return null if the header doesn't exist. Make sure a string is returned.