HTTP request and response for cookies

Chrome for DevelopersAbout 3 min readAug 27, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

HTTP, HTTP request, HTTP response, HTTP headers (request and response), Cookies, Set-Cookie header, Stateless protocol, Client (browser), Server, Request-response cycle, User-Agent header.

HTTP: The Foundation of Web Communication

The video explains HTTP (Hypertext Transfer Protocol) as the fundamental protocol for all web interactions, including loading videos and accessing APIs. HTTP defines the rules for communication between web clients (like browsers) and servers hosting websites and services.

  • Request-Response Cycle: HTTP operates on a simple request-response cycle, analogous to ordering food in a restaurant. The client (browser) sends a request to the server, and the server responds with the requested resource.
  • Example: Visiting cats.example triggers a request to the server, which responds with index.html. The browser parses this HTML, triggering further requests for CSS, JavaScript, and images from cats.example and other sites like catmap.example.

HTTP Headers: Providing Additional Information

HTTP requests and responses can include headers, which provide supplementary information.

  • Request Headers: These headers augment the request from the browser to the server.
    • Example: Accept-Language: en-US: Indicates the user's preferred language (English, United States).
    • Example: User-Agent: Mozilla/5.0 (CrOS...) Chrome/134.0.6998.198: Provides details about the browser and operating system (Mozilla family, ChromeOS, Chrome version 134.0.6998.198). Servers can use the User-Agent string to serve different files based on the platform.
  • Response Headers: These headers accompany the response from the server to the browser, along with the body (the requested resource).

Cookies: Addressing the Stateless Nature of HTTP

HTTP is inherently stateless, meaning each request is treated independently, and the server doesn't automatically remember previous interactions with the same client. Cookies were introduced to solve this problem.

  • Set-Cookie Header: A Set-Cookie header in an HTTP response instructs the browser to store a small piece of text (a name-value pair) called an HTTP cookie.
    • Example: In response to a request for cats.example/images/cat.jpeg, the server might include the header Set-Cookie: theme=tabby. This tells the browser to store a cookie named "theme" with the value "tabby."
  • Subsequent Requests: The browser will then include this cookie in subsequent requests to cats.example until the cookie expires or is removed. This allows the server to maintain information about the user across multiple pages or sessions (e.g., remembering the user's selected theme).

Cookie Workflow Summary

  1. The browser makes a request to a web server.
  2. The server responds with an HTTP response, potentially including a Set-Cookie header.
  3. The Set-Cookie header instructs the browser to store a cookie.
  4. The browser stores the cookie.
  5. In subsequent requests to the same server, the browser includes a Cookie header containing the stored cookie.

Conclusion

HTTP is the foundational protocol for web communication, enabling the request and delivery of resources between clients and servers. While HTTP is stateless, cookies provide a mechanism for servers to maintain information about users across multiple requests, enhancing the user experience and enabling features like personalized settings and session management. The video encourages viewers to explore other videos in the "Cookie Basics" series and resources on the website for a deeper understanding of cookies.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.