Cookie Header

Table of Content

The Cookie HTTP request header contains stored HTTP cookies previously sent by the server with the Set-Cookie header. The Cookie header is optional and can be omitted if the client doesn't have any cookies. The purpose of the cookie is to remember stateful information (such as items added in the shopping cart on an online store) or to record the user's browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past).

Syntax

Cookie: <cookie-list>
Whereby <cookie-list> is a list of name-value pairs in the form of NAME=VALUE; separated by semicolons.

Directives

The Cookie header doesn't have specific directives. Instead it has name-value pairs separated by semicolons.

Examples

Cookie: name=value; name2=value2; name3=value3

This example presents setting multiple cookies where name, name2 and name3 are cookie names while value, value2 and value3 are corresponding values.

Browser Compatibility

Browser Compatibility
Chrome Supported
Firefox Supported
Safari Supported
Opera Supported
Edge Supported

All modern browsers support the Cookie header.

ModHeader is a Chrome extension that can be added to the browser for modifying both request and response headers. You can use it to modify the Cookie header to test or debug your application.

To modify the Cookie header using ModHeader, follow these steps:

  1. Add ModHeader to your Chrome browser.
  2. Click the ModHeader icon beside the URL bar to open it.
  3. Click on '+ Add' to create a new profile.
  4. In the 'Request headers' section, enter 'Cookie' in the 'Name' field, and then your desired cookie information in the 'Value' field, something like 'name=value'.
  5. Now, when you make requests, the Cookie header will include your modifications.

This comes handy when you need to set up mock tests or when you need to debug by emulating certain conditions, like different session states.