unicornAll work
All theoryNetworking

How HTTP works

The language a browser speaks: requests, responses, methods, status codes, headers and cookies.

In a nutshell HTTP is the language a browser speaks to a web server. The browser sends a request ("give me the page"), the server sends a response (the page itself plus service information). Everything you do on the web is a stream of such request-response pairs. Web pentesting is, in essence, reading and altering these messages.

browser server GET /page → ← 200 OK + HTML
Every web interaction is a pair: your request, the server's response.

What HTTP and HTTPS are

HTTP (HyperText Transfer Protocol) is an application-layer protocol (L7 — see OSI & TCP/IP models), a set of rules for exchanging web content. It works on "the client asked, the server answered."

HTTPS is the same HTTP wrapped in TLS encryption. It gives three things:

  1. Confidentiality — an outsider on the path can't read the exchange.
  2. Integrity — the data can't be quietly swapped along the way.
  3. Authenticity — the certificate proves you're talking to that exact site, not a fake.

Analogy: HTTP is a postcard any postman can read. HTTPS is a sealed envelope with the sender's seal.

HTTP is "memoryless" (stateless)

The key feature: HTTP does not remember previous requests. The server handles each request as if seeing this client for the first time. That keeps servers simple and fast, but creates a problem: how does a site "remember" that you're logged in? The answer — cookies and sessions (below).

What a request is made of

Three parts:

1. The request line — method, path, version:

GET /index.html HTTP/1.1

2. Headers — service key-value pairs:

Host: example.com
User-Agent: Mozilla/5.0 ...
Cookie: session=abc123

3. Body — data, if any. Usually empty for GET; for POST (submitting a form) the sent data lives here.

What a response is made of

1. The status line — version and code:

HTTP/1.1 200 OK

2. Headers — content type, length, cookies:

Content-Type: text/html
Set-Cookie: session=abc123
Content-Length: 1024

3. Body — the content itself: an HTML page, an image, JSON.

HTTP methods

A method = what to do with the resource:

Method Action Where the data is
GET retrieve in the URL (after ?)
POST send/create in the request body
PUT replace/create at an address in the body
DELETE delete
HEAD like GET, but headers only, no body

The practical takeaway GET puts parameters right in the link: search.php?q=password. Links end up in browser history, in server logs, in the Referer header. So passwords and tokens are sent by POST (in the body), not by GET.

Status codes

The first digit sets the group:

Code Meaning When you see it
200 OK success the page was served
301 / 302 redirect (permanent / temporary) redirect to another address
401 Unauthorized login needed not logged in
403 Forbidden access denied the path exists, but you may not
404 Not Found not found no such path
500 Internal Server Error the server broke a bug in the site's code

For pentesting: telling 401/403/404 apart matters. 404 — the path isn't there. 403 — the path exists, access is closed (already a finding). 500 — the server choked on your input (sometimes a sign of injection). Response codes are what directory brute-forcing runs on → Directory brute-forcing.

Headers worth knowing

In a request (from the browser):

In a response (from the server):

Cookies and sessions — how a site "remembers" you

Since HTTP is memoryless, a recognition mechanism is needed. That's cookies:

  1. You enter a login/password, the browser sends them by POST.
  2. The server checks and replies: Set-Cookie: session=abc123.
  3. The browser saves that cookie.
  4. On every following request the browser adds Cookie: session=abc123 itself.
  5. From that value the server knows "this is the one who logged in five minutes ago" — and doesn't ask for the password again.

The session cookie is essentially a temporary "pass." And here's the whole point for security: whoever holds a valid session cookie is the user — the password is no longer needed. Hence:

Why this is the foundation of web pentesting

Almost every web attack is a manipulation of HTTP requests:

Without understanding how a request is built, you don't understand what exactly you're editing. That's why HTTP is what you keep coming back to.

This is the whole game for web pentesting Burp Suite lets you pause and edit that request before it arrives; SQLi/XSS slip payloads into it; auth bypass edits a cookie inside it. Understand the request and you understand what you're attacking.

From the rooms · TryHackMe

HTTP in Detail
All theory