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 in Python

In Python's HTTP libraries, headers are typically represented as dictionaries. When using PyFetch, we can access response headers through the headers property of the response object.

Assignment

Complete the get_content_type(resp: HeaderResponse) -> str 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 dictionary .get() method on the response object's headers property to get access to the header you need.

Make sure to return an empty string if the header doesn't exist.