Course / 06 Web basics / Lesson 03 of 08

HTTP methods, headers, status codes, cookies

Estimated time: 15 min reading · 15 min activity

When you open a web page, your browser asks a server for content. The server sends a reply. HTTP, short for Hypertext Transfer Protocol, gives those messages a shared structure so both sides can read them.

The browser's message is a request. The server's reply is a response. Think of the exchange as two questions: what did the browser ask for, and what result did the server report?

This lesson uses readable HTTP/1.1 examples. You will follow one exchange first, then identify the same parts in different messages. HTTP/2 and HTTP/3 represent messages differently, but still use requests, responses, methods, headers, and status codes.

Before you begin

Estimated time
15 min reading, 15 min activity. Setup and optional practice may take longer.
Where you work
Use a browser to read the messages on this page. You do not need to install a tool, start a server, or send a request. The site names and messages are fictional examples.
Without a lab
Every message needed for the activities and checks is printed on this page. You can label the lines on paper or in a text editor. Downloads provide another copy of the examples. Answer checking and saved progress require JavaScript and browser storage.

After this lesson you can:

  • Identify a request's method and path, and a response's status code.
  • Separate headers from the body in an HTTP/1.1 example.
  • Explain the different jobs of Set-Cookie and Cookie.

01Example

In this fictional exchange, the browser asks for /note from note.lab.invalid. The server reports success and returns the text listed. The Request and Response labels separate the two messages; they are not part of HTTP.

Request
GET /note HTTP/1.1
Host: note.lab.invalid

Response
HTTP/1.1 200 OK
Content-Type: text/plain

listed

03Separate the headers from the body

In the response, Content-Type: text/plain tells the browser how to interpret the content that follows. text/plain means plain text. A Content-Type header can describe a body in a request as well as in a response.

A blank line ends the headers. After that line, listed is the response body: the content delivered in this example. Other response bodies can contain HTML, an image, or other data.

A request can also have a body. For example, a browser can use POST to submit data for the server to process. The activity below shows POST sending the text slip. Compare that with the worked GET request, which has no body.

These examples use ordinary line breaks to show the parts of a message. They leave out some details needed to send it, such as how a receiver knows the body's length. Use them to practice reading HTTP; they are not complete messages to send over a connection.

06A second response

The worksheet below contains a new POST exchange. Use what you learned from the GET example to read it. Try each step before reading the answer notes at the bottom of the worksheet.

HTTP activity worksheet
Fictional HTTP/1.1 messages, simplified for reading.
The Request and Response labels are not part of HTTP.
The examples omit details needed to send complete messages over a connection.

Request
POST /bin HTTP/1.1
Host: note.lab.invalid
Content-Type: text/plain

slip

Response
HTTP/1.1 201 Created
Content-Type: text/plain
Set-Cookie: lab-sid=note-42; HttpOnly

created

Before reading the answer notes, identify the method, path, response
status, response body, and cookie name and value.

Answer notes
The request uses POST and the path /bin.
The response status is 201. Its body, after the blank line, is created.
Set-Cookie asks the browser to store lab-sid with the value note-42.
HttpOnly is an attribute, separate from that name and value.

Download the HTTP request and response worksheet

  1. Find the activity request's first line. Write its method and path, then find the Host header. These identify the action requested and the resource it concerns.
  2. Find the activity response's first line. Record the three-digit status code and keep it separate from HTTP/1.1. Here, 201 means the request succeeded and created one or more resources.
  3. Locate the blank line in the response. Everything after it, up to the end of that message, is the body. Record the body separately from the headers.
  4. Find the header that asks the browser to store a cookie. Write the cookie's name and value, leaving HttpOnly in a separate note as an attribute.
  5. Compare your notes with the worksheet: POST requests /bin; the response status is 201; the body is created; and the response asks the browser to store lab-sid with the value note-42.
  6. Keep the browser and server directions in mind for the checks below. This activity finishes with reading and note-taking; it requires no network connection.

07Optional challenge

Allow about ten minutes. Assume the browser accepted the activity cookie and is making another request to the same site and path. Write the request header that would return the cookie, then explain why its name differs from the response header.

Check your reasoning: the request uses Cookie: lab-sid=note-42. The earlier response used Set-Cookie to ask for storage. HttpOnly is an attribute on that response header; it is not repeated as part of the cookie value.

08What to remember

Read a message in order: first line, headers, blank line, and body when present. The request method says what action is requested. The response status code reports the result.

Set-Cookie asks the browser to store a cookie; Cookie sends a stored cookie back on a matching request. Next, the HTTPS lesson explains how the connection can protect these messages while they travel.

09Cards for the checks

The checks below use these cards. They are original fictional text, safe to read anywhere.

Response for check 1Owned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

HTTP/1.1 503 Service Unavailable
Content-Type: text/plain
Retry-After: 120
 
queue status: 200 jobs waiting

Response for check 2Owned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

HTTP/1.1 201 Created
Content-Type: text/plain
Set-Cookie: cart=7; HttpOnly
Cache-Control: no-store
 
added

10Fresh cases for the checks

Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.

Request A — fictional reading fixture; line numbers are labels, not message bytesOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

1 | POST /parcels HTTP/1.1
2 | Host: parcel.lab.invalid
3 | Content-Type: text/plain
4 |
5 | label=GET /archive

Response B — independent fictional response; the empty numbered row preserves the blank separatorOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

1 | HTTP/1.1 410 Gone
2 | Content-Type: text/plain
3 | X-Queue-Count: 200
4 | Cache-Control: no-store
5 |
6 | queue note: 503 items pending
7 | Content-Type: this is body text

Cookie response C — independent fictional response from https://basket.lab.invalid/cartOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

HTTP/1.1 200 OK
Content-Type: text/plain
Set-Cookie: basket=Mint9; HttpOnly
 
saved

Cookie response C — assumptions for the later request, outside the responseOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

For this task: the browser accepts this cookie; it is the only stored cookie.
The next request is to the same HTTPS site and /cart path, before expiry.
Assume all browser settings and cookie matching rules permit sending it.
These simplified reading fixtures omit wire framing details; no request was sent.

11Optional explanation: what did the message establish?

Spend up to five minutes explaining to a partner why a body containing a status-like number cannot replace the response's first line. Then explain which extra assumptions let you predict a cookie's return.

Self-check: identify the response start line, distinguish the blank separator from body content, and describe both cookie directions. Say that a storage request alone does not prove acceptance. This explanation is for your own review; it is not automatically graded.

12Common mistakes

If you cannot tell a request from a response, compare their first lines. These requests begin with a method such as GET or POST. These responses begin with HTTP/1.1 followed by a status code.

If several numbers appear in a response, return to its first line. The status code follows the protocol version. Numbers in headers or body text have other meanings.

If you swap Cookie and Set-Cookie, draw two arrows. Label server to browser as the storage request, and browser to server as the return of the stored value.

If you count a header as body content, locate the blank line. The headers end there; any body begins after it.

References