Section 7: Layer 7 - HTTP, HTTPS & TLS


7.1 HTTP Overview

HTTP (Hypertext Transfer Protocol) is the foundation of data communication on the web.

HTTP Characteristics

  • Application layer protocol (Layer 7)
  • Client-server model (request-response)
  • Stateless (each request is independent)
  • Text-based protocol (human-readable)
  • Uses TCP as transport (port 80 for HTTP, 443 for HTTPS)
HTTP Request-Response Model

Client (Browser)          Server (Web Server)
      |                          |
      |--- TCP Handshake ------->|
      |<-- TCP Handshake --------|
      |                          |
      |--- HTTP Request -------->|
      |    GET /index.html       |
      |                          |
      |<-- HTTP Response --------|
      |    200 OK + HTML content |
      |                          |

7.2 HTTP Versions Comparison

FeatureHTTP/1.0HTTP/1.1HTTP/2HTTP/3
Year1996199720152022
ConnectionNew TCP per requestPersistent (keep-alive)Multiplexed (single TCP)Multiplexed (QUIC/UDP)
Requests per connSequentialSequential (pipelining)Parallel (streams)Parallel (streams)
Header FormatTextTextBinary (compressed)Binary (compressed)
Server PushNoNoYesYes
Head-of-Line BlockingYesYesNo (TCP HOL)No
TransportTCPTCPTCPQUIC (UDP)
EncryptionOptionalOptionalPractical TLSBuilt-in TLS

HTTP/1.1 vs HTTP/2 Visual

HTTP/1.1 (Multiple Connections):

Browser                                                   Server
   |                                                        |
   |===== Connection 1 (TCP) ===== Request 1 =============>|
   |<==================================== Response 1 =======|
   |                                                        |
   |===== Connection 2 (TCP) ===== Request 2 =============>|
   |<==================================== Response 2 =======|
   |                                                        |
   |===== Connection 3 (TCP) ===== Request 3 =============>|
   |<==================================== Response 3 =======|

Limit: ~6 parallel connections per domain


HTTP/2 (Single Multiplexed Connection):

Browser                                                   Server
   |                                                        |
   |============ Single TCP Connection =====================|
   |                                                        |
   |--- Stream 1: Request 1 ------------------------------->|
   |--- Stream 3: Request 2 ------------------------------->|
   |--- Stream 5: Request 3 ------------------------------->|
   |<--------------------------------- Stream 1: Response 1-|
   |<--------------------------------- Stream 5: Response 3-|
   |<--------------------------------- Stream 3: Response 2-|
   |                                                        |

All requests/responses multiplexed on single connection
Responses can arrive out of order

7.3 HTTP Request Structure

HTTP REQUEST FORMAT

+-----------------------------------------------------------------------+
|  REQUEST LINE                                                         |
|  METHOD  SP  REQUEST-URI  SP  HTTP-VERSION  CRLF                     |
|  GET /index.html HTTP/1.1\r\n                                        |
+-----------------------------------------------------------------------+
|  HEADERS                                                              |
|  Header-Name: Header-Value CRLF                                      |
|  Host: www.example.com\r\n                                           |
|  User-Agent: Mozilla/5.0...\r\n                                      |
|  Accept: text/html,application/xhtml+xml\r\n                         |
|  Accept-Language: en-US,en;q=0.9\r\n                                 |
|  Connection: keep-alive\r\n                                          |
+-----------------------------------------------------------------------+
|  BLANK LINE (CRLF)                                                   |
|  \r\n                                                                 |
+-----------------------------------------------------------------------+
|  BODY (optional, for POST/PUT)                                       |
|  username=admin&password=secret                                       |
+-----------------------------------------------------------------------+

CRLF = Carriage Return + Line Feed (\r\n)
SP = Space

7.4 HTTP Methods (Verbs)

MethodSafeIdempotentRequest BodyResponse BodyDescription
GETYesYesNoYesRetrieve resource (most common)
HEADYesYesNoNoSame as GET, no body (headers only)
POSTNoNoYesYesSubmit data/create (forms, file uploads)
PUTNoYesYesYesReplace/create resource (full update)
PATCHNoNoYesYesPartial modification (update specific fields)
DELETENoYesMaybeMaybeRemove resource (delete by identifier)
OPTIONSYesYesNoYesGet allowed methods (CORS preflight)
TRACEYesYesNoYesEcho request back (debugging, often disabled)
CONNECTNoNoNoYesEstablish tunnel (HTTPS proxy tunneling)
  • Safe: Does not modify server state
  • Idempotent: Multiple identical requests = same result

7.5 HTTP Response Structure

HTTP RESPONSE FORMAT

+-----------------------------------------------------------------------+
|  STATUS LINE                                                          |
|  HTTP-VERSION  SP  STATUS-CODE  SP  REASON-PHRASE  CRLF              |
|  HTTP/1.1 200 OK\r\n                                                 |
+-----------------------------------------------------------------------+
|  HEADERS                                                              |
|  Date: Mon, 15 Jan 2026 12:00:00 GMT\r\n                            |
|  Server: Apache/2.4.41\r\n                                           |
|  Content-Type: text/html; charset=UTF-8\r\n                          |
|  Content-Length: 1256\r\n                                            |
|  Cache-Control: max-age=3600\r\n                                     |
|  Connection: keep-alive\r\n                                          |
+-----------------------------------------------------------------------+
|  BLANK LINE (CRLF)                                                   |
|  \r\n                                                                 |
+-----------------------------------------------------------------------+
|  BODY                                                                 |
|  <!DOCTYPE html>                                                      |
|  <html>                                                               |
|  <head><title>Example</title></head>                                 |
|  <body><h1>Hello World</h1></body>                                   |
|  </html>                                                              |
+-----------------------------------------------------------------------+

7.6 HTTP Status Codes

1XX - INFORMATIONAL (Request received, continuing process)

CodeNameDescription
100ContinueClient should continue with request
101Switching ProtocolsServer switching to protocol in Upgrade header
103Early HintsPreload resources while server prepares response

2XX - SUCCESS (Request successfully received and processed)

CodeNameDescription
200OKStandard success response
201CreatedResource created (POST/PUT)
202AcceptedRequest accepted, processing not complete
204No ContentSuccess, but no body to return
206Partial ContentRange request successful

3XX - REDIRECTION (Further action needed)

CodeNameDescription
301Moved PermanentlyResource permanently at new URL (cached)
302FoundTemporary redirect (legacy, see 303/307)
303See OtherRedirect with GET method
304Not ModifiedCached version is still valid
307Temporary RedirectTemporary redirect, preserve method
308Permanent RedirectPermanent redirect, preserve method

4XX - CLIENT ERROR (Request contains bad syntax or cannot be fulfilled)

CodeNameDescription
400Bad RequestMalformed request syntax
401UnauthorizedAuthentication required
403ForbiddenServer refuses to authorize
404Not FoundResource does not exist
405Method Not AllowedHTTP method not supported for resource
408Request TimeoutServer timeout waiting for request
413Payload Too LargeRequest body exceeds server limit
414URI Too LongRequest URI exceeds server limit
429Too Many RequestsRate limiting in effect

5XX - SERVER ERROR (Server failed to fulfill valid request)

CodeNameDescription
500Internal Server ErrorGeneric server error
501Not ImplementedServer doesn’t support functionality
502Bad GatewayInvalid response from upstream server
503Service UnavailableServer temporarily overloaded/down
504Gateway TimeoutUpstream server didn’t respond in time

7.7 Common HTTP Headers

Request Headers

HeaderDescription
Host: www.example.comRequired in HTTP/1.1 (virtual hosting)
User-Agent: Mozilla/5.0...Client application identifier
Accept: text/html, */*Acceptable response content types
Accept-Language: en-USPreferred language
Accept-Encoding: gzip, brSupported compression
Connection: keep-aliveConnection management
Cookie: session=abc123Send cookies to server
Authorization: Bearer <token>Authentication credentials
Referer: https://google.comPrevious page URL
Origin: https://example.comRequest origin (CORS)
Content-Type: application/jsonBody content type (POST/PUT)
Content-Length: 128Body size in bytes

Response Headers

HeaderDescription
Date: Mon, 15 Jan 2026...Response timestamp
Server: nginx/1.18.0Server software
Content-Type: text/htmlResponse body type
Content-Length: 1256Response body size
Content-Encoding: gzipCompression used
Cache-Control: max-age=3600Caching directives
ETag: "abc123"Resource version identifier
Last-Modified: Mon, 14 Jan...Last modification time
Set-Cookie: session=xyzSet cookie on client
Location: /new-pageRedirect destination
Access-Control-Allow-OriginCORS allowed origins

Security Headers

HeaderDescription
Strict-Transport-SecurityForce HTTPS
Content-Security-PolicyControl resource loading
X-Frame-OptionsPrevent clickjacking
X-Content-Type-OptionsPrevent MIME sniffing
X-XSS-ProtectionXSS filter (legacy)

7.8 HTTP Cookies

Cookies maintain state in stateless HTTP.

HTTP/1.1 200 OK
Set-Cookie: session=abc123; Path=/; HttpOnly; Secure; SameSite=Strict
Set-Cookie: user=john; Expires=Wed, 15 Jan 2027 12:00:00 GMT
GET /dashboard HTTP/1.1
Cookie: session=abc123; user=john
AttributeDescription
ExpiresAbsolute expiration date/time
Max-AgeSeconds until expiration
DomainDomains that receive the cookie
PathURL path scope
SecureOnly send over HTTPS
HttpOnlyNot accessible via JavaScript
SameSiteCross-site request control (Strict/Lax/None)
  • Session Cookie: No Expires/Max-Age = deleted when browser closes
  • Persistent Cookie: Has Expires/Max-Age = stored until expiration

7.9 HTTPS and TLS Overview

HTTPS = HTTP + TLS

HTTPS provides:

  • Encryption: Data cannot be read by eavesdroppers
  • Integrity: Data cannot be modified in transit
  • Authentication: Server identity verified via certificate
Protocol Stack Comparison

HTTP (Plaintext)              HTTPS (Encrypted)

Application: HTTP             Application: HTTP
     |                              |
     v                        +-----v-----+
Transport: TCP                | TLS/SSL   |  <-- Encryption Layer
     |                        +-----------+
     v                              |
Network: IP                   Transport: TCP
                                    |
                              Network: IP

Ports:

  • HTTP: Port 80
  • HTTPS: Port 443

7.10 TLS 1.3 Handshake

TLS 1.3 HANDSHAKE (Simplified)

     CLIENT                                              SERVER
        |                                                   |
        |                                                   |
        |   1. ClientHello                                  |
        |   -------------------------------------------->   |
        |   - Supported TLS versions                        |
        |   - Cipher suites                                 |
        |   - Key share (Diffie-Hellman public key)        |
        |   - Random number                                 |
        |                                                   |
        |                                                   |
        |   2. ServerHello + Certificate + Finished         |
        |   <--------------------------------------------   |
        |   - Selected cipher suite                         |
        |   - Server key share                              |
        |   - Server certificate                            |
        |   - Certificate verify (signature)                |
        |   - Finished (encrypted)                          |
        |                                                   |
        |   [Both can now compute shared secret]            |
        |                                                   |
        |   3. Finished                                     |
        |   -------------------------------------------->   |
        |   - Client finished (encrypted)                   |
        |                                                   |
        |                                                   |
        |<============ ENCRYPTED DATA EXCHANGE ===========>|
        |   4. Application Data (HTTP request/response)     |
        |                                                   |

TLS 1.3 Advantages over TLS 1.2

  • 1-RTT handshake (vs 2-RTT in TLS 1.2)
  • 0-RTT resumption possible
  • Removed insecure algorithms (RSA key exchange, RC4, SHA-1)
  • Forward secrecy mandatory
  • Encrypted handshake (after ServerHello)

TLS Version Comparison

FeatureTLS 1.2TLS 1.3
Handshake RTT21 (0-RTT possible)
Key ExchangeRSA, DHE, ECDHE (RSA = no PFS)ECDHE, DHE only (all have PFS)
CiphersMany legacy (CBC, RC4…)Only AEAD ciphers (AES-GCM, ChaCha20)
Handshake EncryptionMostly plaintextEncrypted after ServerHello
Certificate EncryptionAfter handshake (plaintext)During handshake (encrypted)
Session ResumptionSession IDs, Session TicketsPSK-based resumption
  • PFS = Perfect Forward Secrecy
  • AEAD = Authenticated Encryption with Associated Data

7.11 Certificate Chain

TLS CERTIFICATE CHAIN (Trust Hierarchy)

+-------------------------+
|     ROOT CA             |  <-- Pre-installed in OS/browser
|  (Self-signed, trusted) |      (DigiCert, Let's Encrypt, etc.)
+------------+------------+
             |
             | Signs
             v
+-------------------------+
|   INTERMEDIATE CA       |  <-- Signed by Root CA
|   (Signed by Root)      |      (Protects Root key)
+------------+------------+
             |
             | Signs
             v
+-------------------------+
|   SERVER CERTIFICATE    |  <-- Your website's certificate
|   (www.example.com)     |      (Signed by Intermediate)
+-------------------------+

Certificate Contains

  • Subject (domain name, organization)
  • Issuer (CA that signed it)
  • Validity period (not before, not after)
  • Public key
  • Signature algorithm
  • Serial number
  • Extensions (SAN, Key Usage, etc.)

7.12 HTTP/HTTPS in Wireshark

HTTP (Unencrypted - Port 80)

Fully visible in Wireshark - can see all headers and body

Frame 5: HTTP GET Request

Hypertext Transfer Protocol
  GET /index.html HTTP/1.1\r\n
  Host: www.example.com\r\n
  User-Agent: Mozilla/5.0...\r\n
  Accept: text/html,application/xhtml+xml\r\n
  \r\n

HTTPS (Encrypted - Port 443)

You see: TLS handshake, then “Application Data” (encrypted)

Frame 10: TLS Record

Transport Layer Security
  TLS Record Layer: Application Data Protocol: http-over-tls
    Content Type: Application Data (23)
    Version: TLS 1.2 (0x0303)
    Encrypted Application Data: 4a8b2c...
    [Cannot decrypt without keys]

To Decrypt HTTPS in Wireshark

  1. Use pre-master secret log file (browser exports keys)
  2. Edit → Preferences → Protocols → TLS → (Pre)-Master-Secret log
  3. Set SSLKEYLOGFILE environment variable in browser

7.13 Wireshark HTTP/TLS Display Filters

HTTP Filters

FilterDescription
httpAll HTTP traffic
http.requestHTTP requests only
http.responseHTTP responses only
http.request.method == "GET"GET requests
http.request.method == "POST"POST requests
http.request.uri contains "/api"Requests to /api paths
http.host == "example.com"Requests to specific host
http.response.code == 200Successful responses
http.response.code >= 400Client/server errors
http.response.code == 404Not found errors
http.response.code >= 500Server errors
http.content_type contains "json"JSON responses
http.cookie contains "session"Requests with session cookie
http.set_cookieResponses setting cookies
http.user_agent contains "Mozilla"Browser requests
http.content_length > 10000Large responses

TLS/SSL Filters

FilterDescription
tlsAll TLS traffic
tls.handshakeTLS handshake messages
tls.handshake.type == 1ClientHello
tls.handshake.type == 2ServerHello
tls.handshake.type == 11Certificate
tls.record.content_type == 23Application Data
tls.alert_messageTLS alerts (errors)
tls.handshake.extensions.server_nameSNI hostname

TCP Port Filters

FilterDescription
tcp.port == 80HTTP port
tcp.port == 443HTTPS port
tcp.port == 8080Alternative HTTP

Combined Filters

FilterDescription
http.request && ip.src == 192.168.1.100HTTP requests from specific IP
http.response.code >= 400 && http.host == "api.example.com"API errors

7.14 HTTP/2 Specifics

HTTP/2 Frame Structure

HTTP/2 FRAME

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                  Stream Identifier (31)                     |
+-+-------------------------------------------------------------+
|                   Frame Payload (0...)                        |
+---------------------------------------------------------------+

Frame Types

TypeNamePurpose
0x0DATARequest/response body
0x1HEADERSHTTP headers (compressed)
0x2PRIORITYStream priority (deprecated in HTTP/3)
0x3RST_STREAMTerminate a stream
0x4SETTINGSConnection configuration
0x5PUSH_PROMISEServer push notification
0x6PINGKeepalive and RTT measurement
0x7GOAWAYGraceful shutdown
0x8WINDOW_UPDATEFlow control
0x9CONTINUATIONContinue HEADERS

Wireshark HTTP/2 Filters

FilterDescription
http2All HTTP/2 traffic
http2.streamid == 1Specific stream
http2.type == 0DATA frames
http2.type == 1HEADERS frames
http2.header.name == ":method"Method pseudo-header
http2.header.value == "GET"GET requests

7.15 Chapter Summary

Key Takeaways

HTTP BASICS:

  • Request-response protocol on TCP (port 80/443)
  • Stateless, text-based (HTTP/1.x) or binary (HTTP/2+)
  • HTTP/2 multiplexes requests on single connection

HTTP METHODS:

  • GET: Retrieve resource
  • POST: Submit data
  • PUT: Replace resource
  • DELETE: Remove resource
  • HEAD: Get headers only
  • OPTIONS: Get allowed methods

STATUS CODES:

  • 2xx: Success (200 OK, 201 Created)
  • 3xx: Redirect (301 Permanent, 302/307 Temporary)
  • 4xx: Client Error (400 Bad Request, 401, 403, 404)
  • 5xx: Server Error (500 Internal, 502 Bad Gateway, 503)

HTTPS/TLS:

  • HTTPS = HTTP + TLS encryption
  • TLS 1.3: 1-RTT handshake, mandatory PFS, AEAD only
  • Certificate chain: Root CA → Intermediate → Server cert

WIRESHARK:

  • HTTP: Fully visible (http.request, http.response.code)
  • HTTPS: Encrypted (need SSLKEYLOGFILE to decrypt)
  • TLS filters: tls.handshake, tls.alert_message

Previous: 06_Layer7_DNS Next: 08_Layer7_Other_Protocols