HTTP headers are important. They often are the backbone of a caching strategy if done right. That is why they should be tested continuously. The problem with those headers: They are almost invisible to a standard user and usually an external tool is needed to make them visible for reading and checking.

There are many ways to read and check those HTTP headers and we are going to introduce four of them. Google Chrome, cURL, PHP and Leankoala.

1. Check HTTP Headers with Google Chrome

Google Chrome is the most widely used web browser at the moment. So why not use it to check the headers. It’s quite easy and can be done by everyone. Just open the developer toolbar, go to the network tab and reload the page.

After the page has loaded all requests that were triggered can be detected. Just select the one request you want to check and have a look at the HTTP  headers that appear.

HTTP Headers for www.spiegel.de

HTTP Headers for www.spiegel.de

PRO

  • no additional tools needed
  • easy to implement
  • free

CONTRA

  • almost impossible to automate

2. Check HTTP Headers with cURL

cURL is the de facto standard library for making HTTP requests in software projects or on the command line. That is why it is available on most Linux distributions or macOS.

To use cURL on the command line just enter the following command

curl -I http://www.spiegel.de

The result looks something like this

HTTP/1.1 200 OK
Date: Sat, 30 Dec 2017 20:12:07 GMT
Cache-Control: max-age=45
Expires: Sat, 30 Dec 2017 20:12:52 GMT
X-SP-TE: 5001896
X-Robots-Tag: index, follow, noarchive, noodp
Content-Type: text/html;charset=UTF-8
X-SP-AP: 5001888
Vary: Accept-Encoding, isssl
Age: 44
X-SP-PR: 5001888
Connection: keep-alive

Same result as in Google Chrome but on the command line. That can be important when the data is supposed to be proccessed.

PRO

  • easy to implement
  • output that can be handled by other tools, like grep
  • free

CONTRA

  • only usable on the command line

3. Read HTTP Headers with PHP

Using a programming language like PHP is a good choice if the results are to be processed. As mentioned before a lot of languages use libcurl itself to create HTTP requests.

In PHP a simple curl request looks like this:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://www.spiegel.de");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);

$result   = curl_exec($ch);
$headers  = curl_getinfo($ch);

The headers’ variable now contains all the headers as an array.

PRO

  • easy to process data
  • integration in continuous testing platforms possible
  • free

CONTRA

  • programming skills needed

4. Test HTTP Headers with Leankoala

HTTP Heqader CheckeLast but not least we want to introduce the Leankoala HTTP Checker. It was designed to check the HTTP headers of all important URLs in a web project. It is possible to check for the existence of a  single header but also to check if the header equals a given value that can be defined via regular expression.

Leankoala was designed to configure tests instead of writing code. That allows you to set up tests within minutes.

Leankoala comes as a fully automated continuous testing solution that runs all tests every hour or after a deployment. It sends e-mails or informs its users via Slack.

PRO

  • Available as continuous testing server
  • Configuration instead of writing code
  • SaaS – no setup needed

CONTRA

  • not free (but low priced)

So if you want to spare yourself and your developers the manual hassles of HTTP header checks, let’s set up a Leankoala demo for you. 🙂