HTTP/HTTPS Complete Reference
The Hypertext Transfer Protocol (HTTP) is the foundation of the World Wide Web. It defines how web browsers request content from servers and how servers respond. HTTPS, the secure version, adds encryption to protect data in transit. Understanding HTTP/HTTPS thoroughly is essential for web developers, network engineers, and anyone working with networked applications.
HTTP Fundamentals
HTTP is a client-server protocol. Clients (typically web browsers) send requests, and servers send responses. The protocol is stateless, meaning each request-response pair is independent—no stored session state exists in the protocol itself, though applications layer sessions on top.
HTTP operates at the Application layer (Layer 7) of the OSI model, relying on TCP for reliable transport. By default, HTTP uses port 80; HTTPS uses port 443. The protocol has evolved through versions—HTTP/1.0, HTTP/1.1, HTTP/2, and HTTP/3—with each adding performance improvements and new features.
Every HTTP request includes a method indicating the desired action, a URI identifying the resource, headers providing additional context, and optionally a body containing data. Responses include a status code, headers, and optionally a body with the requested content. This simple model supports everything from simple page loads to complex API interactions.
HTTP Methods
HTTP defines several methods (also called verbs) that specify the action the client wants performed. The most common are GET and POST, but PUT, DELETE, PATCH, HEAD, and OPTIONS are also important for comprehensive understanding.
GET requests retrieve data without modifying the server state. When you enter a URL in your browser, it sends a GET request. GET requests can include query parameters in the URL string but should not include request bodies. Browsers cache GET responses, and bookmarks can save GET requests. Safe and idempotent, GET requests can be repeated without changing server state.
POST requests submit data to the server for processing. Form submissions, file uploads, and API calls that create resources typically use POST. Unlike GET, POST requests can include bodies and are not cached. POST is neither safe nor idempotent—submitting the same POST request multiple times may create multiple resources or cause other side effects.
PUT requests create or replace a resource at a specific URI. If the resource exists, PUT replaces it entirely. PUT is idempotent—sending the same PUT request multiple times produces the same result. POST and PUT are often confused: POST creates resources at a server-determined location, while PUT places resources at a client-specified location.
DELETE requests remove a resource. The server should delete the specified resource if it exists. Like PUT, DELETE is idempotent—deleting an already-deleted resource should return success. PATCH applies partial modifications to a resource, differing from PUT's complete replacement.
HEAD requests are identical to GET but return only headers, not the body. Clients use HEAD to check if a resource exists, retrieve metadata, or verify caching without downloading the full content. OPTIONS requests return information about communication options for a given URI, used in CORS preflight requests.
HTTP Status Codes
Status codes are three-digit numbers grouped by category. The first digit indicates the class of response. Understanding status codes helps troubleshoot issues and build robust applications.
1xx codes are informational, indicating the request was received and processing continues. 100 Continue allows clients to send large request bodies after sending headers, confirming the server will accept them. 101 Switching Protocols occurs during WebSocket upgrade or HTTP/2 negotiation.
2xx codes indicate success. 200 OK is the standard success response—the request succeeded. 201 Created indicates a new resource was created, typically following POST or PUT. 204 No Content indicates success with no body, used for DELETE confirmation or actions that return no data.
3xx codes redirect. 301 Moved Permanently tells clients and search engines the resource has a new permanent URL. 302 Found (commonly called "302 redirect") is temporary—the original URL remains valid. 304 Not Modified allows caching when the client already has a current version. 307 Temporary Redirect and 308 Permanent Redirect preserve request method during redirect.
4xx codes indicate client errors. 400 Bad Request means the server cannot understand the request due to malformed syntax. 401 Unauthorized requires authentication (similar to 403 but indicates authentication might help). 403 Forbidden means the server refuses to fulfill the request—authentication will not help. 404 Not Found is the familiar "page not found" error.
Other important 4xx codes include 405 Method Not Allowed (the HTTP method is not supported for this resource), 408 Request Timeout (server timed out waiting for the request), 409 Conflict (request conflicts with server state, like duplicate resource creation), 429 Too Many Requests (rate limiting), and 415 Unsupported Media Type (request body format not supported).
5xx codes indicate server errors. 500 Internal Server Error is a generic error when no more specific code applies. 502 Bad Gateway typically indicates a proxy or gateway received an invalid response from an upstream server. 503 Service Unavailable means the server is temporarily unavailable (overloaded or maintenance). 504 Gateway Timeout indicates an upstream server did not respond in time.
HTTP Headers
HTTP headers provide metadata about requests and responses. They control caching, authentication, content negotiation, and more. Headers follow a simple name: value format and appear before the body.
General headers like Connection control whether the connection persists after the current transaction. Keep-Alive allows persistent connections, reducing connection overhead. Date timestamps when the message was created. Transfer-Encoding indicates how the body is encoded (chunked, compressed).
Request headers sent by clients include Host (required, specifies which website when multiple sites share an IP), User-Agent (identifying the client software), Accept (specifying acceptable response formats), Accept-Language (preferred languages), Accept-Encoding (acceptable compressions), and Authorization (credentials for authentication).
Conditional request headers like If-Modified-Since (only return content if modified since this date), If-None-Match (only return content if ETag differs), and If-Range (allows resuming interrupted downloads) help optimize caching and prevent lost updates.
Response headers from servers include Content-Type (MIME type of the body, like text/html or application/json), Content-Length (size in bytes), Content-Encoding (compression method), ETag (identifier for a specific version of the content), and Last-Modified (when the content was last modified).
Security headers improve browser security. Strict-Transport-Security (HSTS) forces HTTPS connections. Content-Security-Policy prevents XSS by controlling resource loading. X-Frame-Options prevents clickjacking by controlling iframe embedding. X-Content-Type-Options prevents MIME type sniffing.
HTTPS and TLS
HTTPS adds security through TLS (Transport Layer Security), formerly SSL. HTTPS is not a different protocol—it is HTTP over a TLS connection. TLS provides encryption, authentication, and integrity protection.
Encryption prevents eavesdroppers from reading transmitted data. Without TLS, anyone on the network path can capture and read sensitive data like passwords, personal information, and private messages. TLS encrypts all data, making interception useless.
Authentication verifies that you are communicating with the intended server, not an imposter. TLS certificates are issued by trusted certificate authorities (CAs) like DigiCert, Let's Encrypt, and Comodo. Browsers verify certificate chains to confirm servers are legitimate.
Integrity protection detects tampering. TLS adds message authentication codes (MACs) that detect any modification during transit. Attackers cannot modify encrypted data without detection, ensuring you receive exactly what the server sent.
TLS Handshake
The TLS handshake establishes a secure session. The simplified handshake involves the client sending a ClientHello with supported cipher suites and a random number. The server responds with ServerHello (chosen cipher, its random number), its certificate, and potentially a ServerKeyExchange message. The client verifies the certificate, generates a premaster secret, encrypts it with the server's public key, and sends it. Both derive the master secret and session keys, then send Finished messages.
This process adds latency—one to three round trips before any application data flows. TLS 1.3 reduced handshake to one round trip in most cases. Session resumption allows clients who have connected before to skip most handshake steps, resuming previous sessions.
Certificates and CAs form the trust model. Certificate authorities verify domain ownership and issue certificates. Browsers maintain lists of trusted root CAs. When a server presents a certificate signed by a trusted CA, browsers accept it. This chain of trust extends through intermediate certificates to root certificates.
HTTP/2 and HTTP/3
HTTP/2 improved performance over HTTP/1.1 through multiplexing (multiple requests over a single connection), header compression (HPACK), server push (server sends resources before requested), and stream prioritization. These features reduce latency and improve page load times.
Multiplexing allows multiple concurrent requests without head-of-line blocking—requests and responses interleave freely over a single TCP connection. HTTP/1.1 required multiple connections or pipelining (which few implementations supported) to achieve parallelism.
HTTP/3 takes a different approach, using QUIC (which itself uses UDP) instead of TCP. QUIC reduces connection establishment time, eliminates head-of-line blocking at the transport layer, and performs better on lossy networks. HTTP/3 adoption is growing as server and browser support improves.
REST and APIs
REST (Representational State Transfer) is an architectural style for web APIs. RESTful APIs use HTTP methods consistently, treat resources as nouns, and leverage HTTP semantics. Understanding REST helps design and consume web APIs effectively.
REST endpoints should use nouns, not verbs: /users not /getUsers. HTTP methods provide the verbs: GET retrieves, POST creates, PUT replaces, DELETE removes. Response status codes communicate outcomes: 201 for creation, 204 for successful deletion with no content, 400 for client errors.
API versioning allows evolution without breaking existing clients. Common approaches include URL path versioning (/v1/users), query parameter versioning (?version=1), and header versioning. Each has trade-offs in visibility, caching, and client convenience.
Caching and CDNs
Caching dramatically improves web performance. Browsers cache responses locally. Proxies cache responses for multiple users. CDNs cache content at edge locations close to users. Proper cache headers ensure users get fresh content when needed and cached content when appropriate.
Cache-Control headers provide detailed caching instructions. max-age specifies how long to cache. no-cache forces revalidation before using cached content. no-store prevents caching entirely. public marks responses cacheable by any cache; private marks responses for single-user caching only.
ETags provide content versioning. Servers send an ETag (a hash or version identifier) with responses. Clients send If-None-Match with the ETag on subsequent requests. If the content has not changed, servers return 304 Not Modified without a body, saving bandwidth.
CORS
Cross-Origin Resource Sharing (CORS) controls when web pages can request resources from different origins. Same-origin policy (SOP) restricts pages from making requests to different origins by default, preventing certain attacks. CORS provides a controlled way to relax these restrictions.
When a page from https://example.com requests something from https://api.example.com, the browser first sends a preflight OPTIONS request asking for permission. The server responds with CORS headers indicating allowed origins, methods, and headers. If the origin is allowed, the browser proceeds with the actual request.
Access-Control-Allow-Origin specifies which origins can access the resource. Access-Control-Allow-Methods lists permitted HTTP methods. Access-Control-Allow-Headers lists permitted request headers. Access-Control-Allow-Credentials allows cookies and authentication to be sent with cross-origin requests.
WebSockets
While HTTP is request-response based, WebSockets provide persistent bidirectional communication. A WebSocket connection starts as an HTTP request with an Upgrade header. If the server agrees, the connection transforms into a WebSocket, staying open for ongoing communication.
WebSockets are ideal for real-time applications like chat, live updates, and gaming. Once established, either side can send messages without the overhead of HTTP request-response cycles. However, WebSockets lack features like automatic caching and do not work well with CDNs.
Conclusion
HTTP and HTTPS are fundamental to web communication. Understanding methods, status codes, headers, and security enables building robust applications, troubleshooting issues, and implementing modern web features. The protocol continues evolving—HTTP/3 and QUIC improve performance, new headers address emerging needs, and web standards expand what applications can do.
Whether you are debugging a failing API call, optimizing website performance, or designing a new web service, deep HTTP knowledge proves invaluable. The investment in understanding these concepts pays dividends across many technical roles and projects.