HTTP HTTPS TLS Web

HTTP/HTTPS Under the Hood: Headers, Methods, and TLS

LP
Lisa Park
Backend Engineer
Mar 05, 2025
14 min read

What You'll Learn

HTTP/HTTPS protocol internals — request/response cycle, methods, status codes, headers, cookies, TLS handshake, HTTP/2 vs HTTP/3, and practical debugging with curl.

The HTTP Request/Response Cycle

HTTP Request
GET /api/users?page=1 HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGci...
Accept: application/json
Content-Type: application/json
User-Agent: Mozilla/5.0 (...)
Connection: keep-alive
Cache-Control: no-cache

{body here for POST/PUT}
HTTP Response
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 1234
Cache-Control: max-age=300
X-Request-ID: abc123-def456
Set-Cookie: session=xyz; HttpOnly
Strict-Transport-Security: max-age=31536000

{"users": [...], "total": 100}

HTTP Methods

MethodPurposeBodyIdempotent
GETRetrieve resourceNo✅ Yes
POSTCreate resourceYes❌ No
PUTReplace entire resourceYes✅ Yes
PATCHPartial updateYes❌ No
DELETERemove resourceOptional✅ Yes
HEADLike GET but no body (metadata only)No✅ Yes
OPTIONSCORS preflight, allowed methodsNo✅ Yes

HTTP Status Codes

2xx — Success
200 OK
201 Created
204 No Content
206 Partial Content
3xx — Redirects
301 Moved Permanently
302 Found (temp redirect)
304 Not Modified (cache)
307 Temporary Redirect
4xx — Client Errors
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
429 Too Many Requests
5xx — Server Errors
500 Internal Server Error
502 Bad Gateway (upstream error)
503 Service Unavailable
504 Gateway Timeout

HTTPS & TLS Handshake

1
1. Client Hello
Client sends supported TLS versions, cipher suites, and a random number.
2
2. Server Hello
Server picks TLS version + cipher, sends its SSL certificate and a random number.
3
3. Certificate Verification
Client verifies server certificate against trusted CAs. Extracts server's public key.
4
4. Key Exchange
Client generates a pre-master secret, encrypts it with server's public key, sends it.
5
5. Session Keys
Both sides derive session keys from the pre-master secret + both random numbers.
6
6. Finished
Both sides send "Finished" message encrypted with session key. Secure channel established!

curl — Your HTTP Swiss Army Knife

bash — curl reference
# Basic GET
curl https://api.example.com/users

# With headers
curl -H "Authorization: Bearer TOKEN" \
     -H "Accept: application/json" \
     https://api.example.com/users

# POST with JSON body
curl -X POST \
     -H "Content-Type: application/json" \
     -d '{"name":"John","email":"john@example.com"}' \
     https://api.example.com/users

# Show response headers only
curl -I https://example.com

# Show request + response headers (verbose)
curl -v https://example.com

# Follow redirects
curl -L https://example.com

# Save to file
curl -o output.json https://api.example.com/data

# HTTP timing breakdown (useful for perf testing!)
curl -w "\n\nDNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" \
     -o /dev/null -s https://example.com

# Test with custom Host header (useful for testing behind load balancer)
curl -H "Host: api.example.com" http://10.0.0.5/health

# Test SSL certificate
curl -vI https://example.com 2>&1 | grep -E "subject|issuer|expire"

Important HTTP Headers

HeaderPurposeExample
Content-TypeBody formatapplication/json
AuthorizationAuth credentialsBearer <token>
Cache-ControlCaching directivesmax-age=3600, no-cache
CORS: Access-Control-Allow-OriginCross-origin permissionshttps://app.example.com
Strict-Transport-SecurityForce HTTPS (HSTS)max-age=31536000
X-Forwarded-ForReal client IP (via proxy)203.0.113.195
Content-Security-PolicyPrevent XSS attacksdefault-src 'self'

Keep Reading

D
DevOps

Docker Networking Demystified: Bridge, Host & Overlay

8 min read Read More
C
Cloud

AWS IAM Roles vs Users vs Policies

10 min read Read More
P
Programming

Understanding Python's GIL & Multiprocessing

14 min read Read More