HTTP headers are key-value pairs that are included in both HTTP requests and HTTP responses. They are sent before the actual data (the body) and are separated from the body by a blank line. Headers are text-based, making them relatively easy to read and understand.
Here's a simplified example of what some HTTP headers might look like in a request:
GET /index.html HTTP/1.1Host: www.example.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)Accept: text/html,application/xhtml+xml
And here's an example of some headers in a response:
Content-Type:: Specifies the type of content in the response body (e.g., text/html; charset=UTF-8, image/jpeg, application/json). This tells the browser how to interpret the data.
Content-Length:: Specifies the size of the response body in bytes.
Server:: Identifies the web server software being used (e.g., Apache/2.4.41, nginx/1.18.0).
Date:: Indicates the date and time the response was generated.
Cache-Control:: Provides directives for caching the response (e.g., public, private, max-age).
Expires:: Specifies a date and time after which the response should be considered stale.
Last-Modified:: Indicates the date and time the resource was last modified.
Set-Cookie:: Sends cookies from the server to the client.
Location:: Used in redirection responses (3xx status codes) to specify the new URL.
ETag: An identifier for a version of the resource.
Test Your Knowledge
Take a quiz to reinforce what you've learned
Exam Preparation
Access short and long answer questions for written exams