Open In App

Content-Length - HTTP headers

Last Updated : 25 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

HTTP headers are used to transmit additional information in an HTTP request or response. One such important header is the Content-Length header, which is responsible for indicating the size of the entity-body, measured in bytes (octets). This information is used by the recipient to know the exact length of the body content that follows the headers.

What is the Content-Length Header?

The Content-Length header defines the size of the HTTP message body (in bytes) sent to the recipient. This header is especially useful in cases where the recipient needs to know how much data to expect. The size is defined in decimal format.

The Content-Length header is considered a forbidden header name, meaning you cannot modify or set it programmatically in certain environments, such as using JavaScript within browsers.

Syntax:

Content-Length: <length>

Directive:

This header accepts a single directive mentioned above and described below:

  • Length: It defines the length of entity-body in decimal no of octets or say bytes.

Example:

content-length: 6553
content-length: 54138

How to Check Content-Length in Action

  1. Right-click on the page and select Inspect or use the keyboard shortcut Ctrl + Shift + I (Windows) or Cmd + Option + I (Mac).
  2. Go to the Network tab in the developer tools.
  3. Reload the page or perform an action that sends a request.
  4. Click on the request and examine the Headers tab to find the Content-Length header under "Response Headers" or "Request Headers."

Similar Reads