Detailed Notes on HTTP
Detailed Notes on HTTP
HTTP (HyperText Transfer Protocol) is the backbone of data communication on the World Wide Web.
It is an application-layer protocol designed for transmitting hypermedia documents, such as HTML,
between clients and servers. Its simplicity, flexibility, and ability to support multiple types of content
have made it the most widely used protocol on the web.
Introduction to HTTP
HTTP defines the rules and formats for communication between a client (usually a web browser) and
a server (which hosts websites or other resources). HTTP is stateless by design, meaning each
request-response pair is independent, and the server does not retain information about previous
interactions.
Port Used: HTTP typically operates on port 80. HTTPS, the secure version of HTTP, operates
on port 443.
o Client Sends a Request: The client (browser or application) sends an HTTP request to
the server, asking for a specific resource or performing an action.
o Server Sends a Response: The server processes the request and sends back an HTTP
response containing the requested resource or an error message.
2. Stateless Protocol
HTTP Connections
1. Non-Persistent Connections
Disadvantages: High overhead due to frequent connection setups and teardowns, leading to
increased latency.
2. Persistent Connections
A single TCP connection is reused for multiple request-response pairs.
Advantages: Reduces latency and resource usage by avoiding the overhead of setting up new
connections.
HTTP messages are exchanged between the client and server in two formats: request messages and
response messages.
Request Line: Specifies the HTTP method, the resource URL, and the HTTP version. For
example:
Header Lines: Provide additional metadata, such as the type of content the client accepts or
authentication credentials. For example:
Host: www.example.com
User-Agent: Mozilla/5.0
Body (Optional): Used in methods like POST or PUT to send data to the server.
Status Line: Includes the HTTP version, status code, and status phrase. For example:
HTTP/1.1 200 OK
Header Lines: Provide metadata about the response, such as the content type and length.
For example:
Content-Type: text/html
Content-Length: 2048
HTTP Methods
HTTP defines several methods, also known as verbs, to specify the desired action:
Method Description
1. Static Documents
2. Dynamic Documents
3. Active Documents
o Contain code that runs on the client side, such as JavaScript or Java applets.
500-599 Server errors 500 Internal Server Error, 503 Service Unavailable
Features of HTTP
1. Cookies
Cookies help overcome HTTP's stateless nature by storing small amounts of data on the client side.
They are used for:
2. Caching
HTTP supports caching to reduce latency and improve performance by storing copies of responses:
Proxy Servers: Act as intermediaries that cache responses for multiple clients.
3. Security
HTTP lacks built-in security. HTTPS addresses this by running HTTP over SSL/TLS, providing:
4. Content Negotiation
Clients can specify preferred content types, languages, and encodings in the request headers. The
server delivers content accordingly, ensuring compatibility.
Versions of HTTP
HTTP/1.0
HTTP/1.1
HTTP/2
Enabled multiplexing to handle multiple streams over a single connection, reducing latency.
HTTP/3
Conclusion
HTTP has evolved significantly since its inception, adapting to the growing demands of the modern
web. From its simple stateless design to its advanced features like persistent connections and
content negotiation, HTTP continues to be the foundation of web communication. Its flexibility and
extensibility ensure its relevance in the ever-changing digital landscape.
Introduction to DNS
DNS is an application-layer protocol that maps domain names, such as "www.example.com," to their
corresponding IP addresses (e.g., 192.0.2.1). Since IP addresses are challenging to remember, DNS
simplifies the process for users by allowing them to use easy-to-remember names instead.
Port Used: DNS primarily operates on UDP port 53, with TCP port 53 used for specific tasks
like zone transfers.
DNS is structured as a hierarchical system consisting of several key components and layers.
1. Domain Namespace
The domain namespace is the logical structure of DNS, organized hierarchically like an inverted tree.
Root Domain: Represented by a dot ("."), it is the top-most level of the DNS hierarchy.
Top-Level Domains (TLDs): Located below the root domain and include categories such as:
Zones: DNS zones are portions of the DNS namespace managed by a specific organization or
entity. A zone can consist of one domain or multiple subdomains.
Zone Files: Contain DNS records for a particular zone, specifying mappings and
configurations.
3. DNS Records
DNS records provide information about a domain, including its IP addresses and services. Common
record types include:
TXT Provides arbitrary text data for a domain (e.g., SPF records).
DNS resolution is the process of converting a domain name into its corresponding IP address. It
involves several steps and types of DNS servers.
1. Recursive Resolution
In recursive resolution, a DNS resolver handles the entire query process on behalf of the client,
ensuring it receives a final answer.
2. Iterative Resolution
In iterative resolution, the client makes queries to multiple DNS servers, receiving referrals to the
next server until the final answer is obtained.
Recursive Resolver Handles client queries and performs recursive lookups if needed.
Authoritative Server Provides the definitive answer for the domain in question.
1. Query Sent: The client sends a query to a recursive resolver (e.g., ISP’s DNS server).
2. Root Server Interaction: If the resolver does not have the answer, it queries a root server.
3. TLD Server Interaction: The root server directs the query to the appropriate TLD server.
4. Authoritative Server Interaction: The TLD server points to the domain’s authoritative name
server.
5. Response Received: The authoritative server responds with the requested record (e.g., an IP
address).
Types of DNS Queries
Recursive Query The resolver takes full responsibility for finding the answer.
Iterative Query The client queries multiple servers, receiving referrals until an answer is found.
DNS Caching
To improve performance and reduce query traffic, DNS employs caching mechanisms:
Local Cache: Stored by the client or operating system for previously resolved queries.
Recursive Resolver Cache: Stored by resolvers to handle subsequent requests for the same
domain efficiently.
Time to Live (TTL): Specifies the duration for which a DNS record can be cached before being
refreshed.
DNS Security
DNS was not originally designed with security in mind, making it vulnerable to various threats.
Measures to enhance DNS security include:
DNSSEC adds cryptographic signatures to DNS records, ensuring their authenticity and integrity. Key
components include:
DNS Spoofing/Cache Poisoning: Attackers inject false DNS records into a resolver’s cache.
3. Mitigation Techniques
1. Web Browsing: Translating domain names into IP addresses for accessing websites.
2. Email Delivery: Resolving MX records to route emails to the correct mail servers.
3. Content Delivery Networks (CDNs): Using DNS to direct users to the nearest server for faster
content delivery.
4. Reverse DNS (rDNS): Mapping IP addresses back to domain names, often used for logging
and authentication.
Dynamic DNS updates DNS records in real-time, allowing changes in IP addresses (common with
DHCP) to be reflected automatically.
2. Split-Horizon DNS
Provides different DNS responses based on the origin of the query (e.g., internal vs. external
networks).
3. Anycast DNS
Uses multiple servers with the same IP address to provide redundancy and reduce latency by
directing queries to the nearest server.
Conclusion
DNS is an indispensable component of the internet, enabling user-friendly domain names and
efficient routing. Despite its foundational simplicity, DNS has evolved to include advanced features
like caching, security (DNSSEC), and dynamic updates, ensuring its scalability and relevance in
modern networking environments.