HTTP, TLS & Web Performance

HTTP Explained: Requests, Responses and Headers

Learn what travels between a browser and a server, how to read each part and how to inspect real exchanges yourself.

Key takeaways

  • Every HTTP exchange is one request from a client and one final response from a server.
  • A request names a method and a target, while a response leads with a three-digit status code.
  • Headers are name-and-value lines that control caching, formats, identity, security and more.
  • HTTP is stateless, so cookies and tokens are what let a server recognize you across requests.
  • Browser developer tools and curl show you the real messages, which beats guessing.

HTTP, the Hypertext Transfer Protocol, is the set of rules your browser and a web server use to talk. The browser sends a request that names an action and a resource. The server sends back a response that says how it went, usually with some content attached.

Both messages have the same basic shape: a first line that states the point, a set of headers that describe the details, and an optional body that carries data. Once you can read those three parts, most web problems become much easier to understand.

The client and server roles

The client is whatever starts the conversation: a browser, a phone app, a script or another server. The server is the program that waits for requests and answers them. The same machine can be a server in one exchange and a client in the next, which happens whenever a web application calls a payment service or a database gateway. The client and server model underlies nearly everything you do online.

Before any HTTP flows, the client has to find the server and open a connection. It looks up the hostname in DNS, connects to an address and port, and for https addresses sets up encryption with TLS. Only then does it send the request.

One page request from start to finish
Browser DNS resolver Web server Where is www.example.com? 1 Here is its IP address 2 Open connection and set up TLS 3 GET /guides/ request 4 200 OK with headers and HTML 5 Requests for CSS, scripts, images 6 Browser DNS resolver Web server Where is www.exam ple.com? 1 Here is its IP address 2 Open connection and set up TLS 3 GET /guides/ request 4 200 OK with headers and HTML 5 Requests for CSS, scripts, images 6

What a request looks like

In HTTP/1.1, a request is readable text. Here is a typical one:

GET /guides/routers?lang=en HTTP/1.1
Host: www.example.com
User-Agent: ExampleBrowser/1.0
Accept: text/html
Accept-Language: en-US
Accept-Encoding: gzip, br
Connection: keep-alive

The first line is the request line. It holds the method (GET), the target (the path and any query string) and the protocol version. The method says what you want done: GET reads, POST submits, DELETE removes, and so on. Each has its own promises, covered in the guide to HTTP methods.

Headers follow, one per line. Host is mandatory in HTTP/1.1 because one IP address often serves many websites, and the server needs to know which one you mean. A blank line marks the end of the headers. A GET normally has no body. A form submission or an API call that creates something puts its data after that blank line.

What a response looks like

The server answers with the same layout:

HTTP/1.1 200 OK
Date: Sat, 05 Dec 2026 12:00:00 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 5120
Cache-Control: max-age=300
ETag: "a1b2c3"

<!doctype html>
...

The status line gives the version and a status code. The code is the part software acts on. The short phrase after it is only a label for humans, and newer HTTP versions drop it entirely.

Codes are grouped by their first digit: informational (1xx), success (2xx), redirection (3xx), client error (4xx) and server error (5xx). You can read more in status codes explained by family, or look one up in the HTTP status reference.

The anatomy of the messages

The parts of an HTTP request
POST 1 /comments 2 HTTP/1.1 3 Content-Type: application/json 4 {"text": "Hello"} 5 Method The action the client is asking for. 1 Target The path and query naming the resource. 2 Version The dialect of the protocol in use. 3 Header Metadata about the message, one name and value per line. 4 Body The data itself, present when there is something to send. 5 POST 1 /comments 2 HTTP/1.1 3 Content-Type: application/json 4 {"text": "Hello"} 5 Method The action the client is asking for. 1 Target The path and query naming the resource. 2 Version The dialect of the protocol in use. 3 Header Metadata about the message, one name and value per line. 4 Body The data itself, present when there is something to send. 5

A body can be anything: HTML, JSON, an image, a video segment or a compressed archive. HTTP does not care what the bytes mean. The Content-Type header tells the receiver how to interpret them, using a media type such as text/html, application/json or image/png.

The receiver also needs to know where the body ends. In HTTP/1.1, that comes from Content-Length, from chunked transfer coding (the body arrives in labeled pieces, ending with an empty one), or in some responses from the connection closing. HTTP/2 and HTTP/3 handle this with their own framing.

Headers by job

There are many headers, but they cluster into a handful of purposes.

Job Request headers Response headers
Routing Host Location
Format negotiation Accept, Accept-Language, Accept-Encoding Content-Type, Content-Encoding, Vary
Caching If-None-Match, If-Modified-Since Cache-Control, ETag, Last-Modified
Identity Authorization, Cookie WWW-Authenticate, Set-Cookie
Context User-Agent, Referer, Origin Server, Date

Header names are not case-sensitive. Content-Type and content-type mean the same thing, and HTTP/2 and HTTP/3 require lowercase on the wire.

Treat request headers as claims. A client can send any User-Agent or Referer it likes, so a server should never base a security decision on them alone. To see what your own browser sends, open the request header echo.

Who sits between you and the server

A request rarely travels straight to the program that builds the page. A company network may send it through a forward proxy. The website may place a content delivery network, a load balancer and a reverse proxy in front of its application. Each of these reads the HTTP message and may add headers, answer from a cache or pass it along.

That explains headers you never set, such as Via, Age or X-Forwarded-For, the last being a widely used way for a proxy to tell the server which client address it saw. It also explains why an error page can come from a layer the site's developers did not write. Reverse proxies explained shows what these intermediaries do.

With HTTPS, an ordinary network device between you and the site cannot read or alter the messages. A layer that the site itself uses, such as its CDN, can, because it holds a certificate for the site and ends the encrypted connection there.

Statelessness and how sites remember you

HTTP is stateless: each request stands alone, and the protocol itself does not link it to the one before. That design makes servers easier to scale, because any of several identical machines can handle the next request.

Sites still need to know who you are, so they add state on top. The usual method is a cookie. The server sends Set-Cookie with an identifier, and the browser returns it in a Cookie header on later requests to that site. APIs often use an Authorization header carrying a token instead. The details, including the flags that protect cookies, are in how cookies work in HTTP.

Connections and versions

Opening a connection costs time, so HTTP/1.1 keeps connections open for reuse by default. It still sends responses on a connection in the order the requests went out, which means one slow answer holds up the rest.

HTTP/2 lets many exchanges share one connection at once and compresses headers. HTTP/3 does the same over QUIC, a transport built on UDP, so a lost packet delays only the stream it belonged to. The methods, status codes and header meanings stay the same across versions, which is why your application code rarely needs to know which one is in use. See HTTP/1.1 vs. HTTP/2 vs. HTTP/3 for the differences.

When the connection is wrapped in TLS, you have HTTPS. Someone watching the network can typically still see which server address you reached, and often the hostname, but not the path, headers or body. HTTPS and TLS explained covers what that protects.

Seeing real HTTP for yourself

In the browser

Open developer tools (often with F12, or Ctrl+Shift+I on Windows and Linux, Option+Command+I on macOS), choose the Network tab and reload the page. Click any entry to see its request headers, response headers, status and timing. Developer tools for non-developers walks through the panel.

With curl

curl comes with macOS, most Linux distributions and recent versions of Windows. In Windows PowerShell 5.1, type curl.exe so you get the real program and not a built-in alias.

# Show the response headers along with the body
curl -i https://www.example.com/

# Ask for headers only, using the HEAD method
curl -I https://www.example.com/

# Show the whole conversation, including connection setup
curl -v https://www.example.com/

In verbose output, lines beginning with > are what you sent, lines beginning with < are what came back, and lines beginning with * are notes from curl itself. Using curl to understand web requests has more recipes.

Reading an exchange when something breaks

A fixed order saves time when a page misbehaves:

  1. Did you get a response at all? A timeout or refused connection happens below HTTP, in DNS, the network or the server's listening port.
  2. What is the status code? A 4xx points at the request. A 5xx points at the server or something behind it.
  3. Who answered? Headers such as Server or Via, and the style of the error page, can show that a proxy or content delivery network replied.
  4. Was it cached? An Age header means a shared cache stored the response some seconds ago.
  5. Is the content labeled correctly? A wrong Content-Type can make a browser download a page or refuse to run a script.

Say a stylesheet stops applying after a deployment. In the Network tab you find its request returned 200 with Content-Type: text/html. The server is sending an HTML error or fallback page where the CSS should be, so the thing to fix is the file path or the server's routing rule.

Common questions

Is HTTP the same thing as the internet?

No. HTTP is one application protocol that runs over the internet. Email, DNS, online games and many other services use their own protocols. The internet and the web are different layers of the same picture.

What is the difference between a URL and a request?

A URL is an address. The browser takes it apart and uses the pieces to build a request: the hostname goes into Host, and the path and query go into the request line. The fragment after # stays in the browser and is never sent.

Can one page load involve many requests?

Almost always. The first response is usually HTML that refers to stylesheets, scripts, fonts and images, and scripts often fetch more data afterward. Each of those is its own request and response with its own status and headers.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in HTTP, TLS & Web Performance →

Latest news on this topic