Introduction to HTTP

Computer Networks - Undergraduate Quiz

12 Questions 4 Basic | 4 Descriptive | 4 Analytical HTTP Protocol Fundamentals

🎯 Basic Questions

1
What does HTTP stand for?
A. HyperText Transfer Protocol
B. HighText Transfer Protocol
C. HyperText Transmission Protocol
D. HostText Transfer Protocol
Correct Answer: A. HyperText Transfer Protocol
Explanation: HTTP stands for HyperText Transfer Protocol. It is the foundation of data communication on the World Wide Web, designed to transfer hypertext documents (HTML) between clients (browsers) and servers. The protocol was developed by Tim Berners-Lee at CERN in 1989 and has become the standard protocol for web communications.
2
Which HTTP method is used to retrieve data from a server without modifying server state?
A. POST
B. GET
C. PUT
D. DELETE
Correct Answer: B. GET
Explanation: The GET method is used to retrieve data from a server. According to HTTP specifications [^17^], GET is both a safe method (does not modify server state) and an idempotent method (multiple identical requests produce the same result). It is the most common HTTP method used when browsing websites, as it simply requests a representation of the specified resource without causing any side effects on the server.
3
What is the default port number for HTTP?
A. 443
B. 8080
C. 80
D. 21
Correct Answer: C. 80
Explanation: The default port number for HTTP is 80. Port 443 is used for HTTPS (HTTP Secure), port 8080 is commonly used as an alternative HTTP port for proxy servers or development, and port 21 is used for FTP (File Transfer Protocol). When you type a URL without specifying a port (e.g., http://example.com), the browser automatically assumes port 80.
4
Which HTTP status code indicates that a requested resource was not found on the server?
A. 200 OK
B. 500 Internal Server Error
C. 404 Not Found
D. 403 Forbidden
Correct Answer: C. 404 Not Found
Explanation: The 404 Not Found status code indicates that the server cannot find the requested resource [^10^]. This is one of the most common HTTP errors encountered when browsing. The 200 OK code indicates success, 500 indicates a server-side error, and 403 indicates that the client is authenticated but lacks permission to access the resource. The 404 error belongs to the 4xx class of client error responses.

📝 Descriptive Questions

5
Describe the difference between HTTP request headers and response headers, providing two examples of each.
Sample Answer:
HTTP Request Headers: These are sent by the client (browser) to the server and contain metadata about the request, client capabilities, and what the client expects in return [^11^][^13^]. They help the server understand how to process the request.

Examples:
1. User-Agent: Identifies the client software (browser type, version, operating system) making the request. Example: User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
2. Accept: Specifies what content types the client can understand. Example: Accept: text/html, application/json

HTTP Response Headers: These are sent by the server back to the client and provide metadata about the response, including information about the server and how the client should handle the returned data [^15^].

Examples:
1. Content-Type: Indicates the media type of the response body. Example: Content-Type: text/html; charset=UTF-8
2. Server: Contains information about the server software handling the request. Example: Server: Apache/2.4.41 (Ubuntu)
6
Explain the difference between the POST and PUT HTTP methods in terms of their purpose and idempotency.
Sample Answer:
Purpose:
POST is used to create a new resource on the server. When you submit a form or upload a file, you typically use POST. The server processes the request and creates a new resource, returning a 201 (Created) status code on success [^12^][^16^].
PUT is used to replace/update an existing resource entirely. It requires the client to send the complete representation of the resource [^17^].

Idempotency:
POST is NOT idempotent: Making the same POST request multiple times will create multiple resources. For example, submitting an order form twice creates two separate orders.
PUT is idempotent: Making the same PUT request multiple times has the same effect as making it once. If you update a user's profile with PUT, sending the same update 10 times results in the same final state as sending it once [^17^].

This idempotent nature of PUT makes it safer for network retries—if a PUT request fails due to network issues, the client can safely retry without worrying about creating duplicate resources.
7
Describe the five classes of HTTP status codes and provide one example from each class.
Sample Answer:
HTTP status codes are grouped into five classes based on the first digit [^10^][^3^]:

1xx - Informational: Indicates that the request was received and the server is continuing the process.
• Example: 100 Continue - The server has received the request headers and the client should proceed to send the request body.

2xx - Success: Indicates that the request was successfully received, understood, and accepted.
• Example: 200 OK - The request was successful, and the server returned the expected response [^14^].

3xx - Redirection: Indicates that the client needs to take additional action to complete the request.
• Example: 301 Moved Permanently - The requested resource has been permanently moved to a new URL.

4xx - Client Error: Indicates that there was an error on the client's side (malformed request, unauthorized, or resource not available).
• Example: 404 Not Found - The server cannot find the requested resource [^10^].

5xx - Server Error: Indicates that the server failed to fulfill a valid request due to an internal error.
• Example: 500 Internal Server Error - A generic error message indicating an unexpected condition on the server [^14^].
8
Explain the structure of an HTTP request message, identifying its four main components.
Sample Answer:
An HTTP request message consists of four main components [^15^]:

1. Request Line (Start Line): The first line of the message that contains three elements:
HTTP Method: Indicates the action to perform (GET, POST, PUT, DELETE, etc.)
Request URI: The path to the resource (e.g., /index.html or /api/users)
HTTP Version: The protocol version (e.g., HTTP/1.1 or HTTP/2)
Example: GET /index.html HTTP/1.1

2. HTTP Headers: Optional key-value pairs that provide metadata about the request. Headers include information such as:
• Host (required in HTTP/1.1): The domain name of the server
• User-Agent: Information about the client browser
• Accept: Content types the client can handle
• Content-Type: Format of the request body (for POST/PUT)

3. Empty Line (CRLF): A blank line that separates the headers from the message body, indicating the end of the header section.

4. Message Body (Optional): Contains data sent to the server, typically used with POST, PUT, or PATCH requests. This could be form data, JSON, XML, or file uploads. GET requests typically do not have a body.

🔍 Analytical Questions

9
Analyze the following scenario: A web developer uses GET requests to delete user accounts by implementing URLs like /delete-user?id=123. Identify the security vulnerabilities in this approach and explain why this violates HTTP principles.
Sample Answer:
Security Vulnerabilities:

1. Cross-Site Request Forgery (CSRF) Attacks: Since GET requests can be triggered simply by visiting a link (via <a> tag, image src, or iframe), an attacker could embed a link like <img src="http://example.com/delete-user?id=123"> on their website. When a logged-in user visits that site, their browser automatically sends the GET request, deleting their account without their knowledge [^16^].

2. Accidental Execution: Search engine crawlers, browser prefetching, or even browser history restoration could trigger the deletion unintentionally.

3. URL Exposure: GET parameters are visible in browser history, server logs, and referrer headers, exposing sensitive deletion operations.

HTTP Principle Violations:

According to RFC specifications and REST principles [^12^][^17^]:
Safe Methods: GET is classified as a "safe" method, meaning it should not modify server state. Safe methods are intended only for retrieval operations.
Semantic Correctness: HTTP methods have specific meanings. GET means "retrieve," while DELETE means "remove." Using GET for deletion violates the protocol's semantic conventions, making the API unpredictable and harder to secure.
Idempotency Misuse: While GET should be idempotent (no side effects), using it for deletion creates non-idempotent side effects while masquerading as a safe operation.

Correct Approach: Use the DELETE method with proper authentication and CSRF tokens for deletion operations.
10
Compare and contrast the 401 (Unauthorized) and 403 (Forbidden) status codes. In what scenarios would each be appropriate, and why is the distinction important for security?
Sample Answer:
401 Unauthorized:
Meaning: Authentication is required but has not been provided or is invalid [^3^][^14^].
Scenario: A user tries to access their profile page without logging in, or provides incorrect login credentials.
Action Required: The client must authenticate (provide valid credentials) to access the resource.
WWW-Authenticate Header: The server typically includes this header indicating what authentication scheme to use (e.g., Basic, Bearer).

403 Forbidden:
Meaning: The server understands the request and the client is authenticated, but the client does not have permission to access the resource [^14^].
Scenario: A regular user tries to access the admin dashboard, or a user tries to view another user's private data.
Action Required: No authentication change will grant access; the client lacks the necessary authorization/permissions.

Why the Distinction Matters for Security:

1. Clear Communication: 401 tells the client "you need to log in," while 403 says "you're logged in but can't access this." This distinction helps clients handle responses appropriately—redirecting to login vs. showing an access denied message.

2. Information Disclosure: Returning 403 for unauthenticated users reveals that a resource exists but is protected, which could be sensitive information. Sometimes 404 is used instead of 403 to avoid revealing resource existence.

3. Attack Surface Reduction: Proper use prevents brute force attacks. A 401 response encourages retry with credentials, while 403 indicates no amount of credential guessing will help, potentially stopping attackers from continuing attempts.
11
Analyze the following HTTP response and identify potential issues or security concerns:

HTTP/1.1 200 OK
Server: Apache/2.4.41 (Ubuntu)
X-Powered-By: PHP/7.4.3
Content-Type: text/html; charset=UTF-8
Set-Cookie: sessionid=abc123; Path=/
Cache-Control: public, max-age=3600
Content-Length: 1240
Sample Answer:
Security Issues and Concerns:

1. Information Disclosure (Server Header): The Server header reveals the exact server software (Apache 2.4.41) and operating system (Ubuntu). This information helps attackers identify known vulnerabilities specific to these versions [^11^].
Recommendation: Configure the server to hide or obfuscate version information (e.g., "Server: Apache").

2. Technology Exposure (X-Powered-By): The X-Powered-By header exposes that PHP version 7.4.3 is being used. This is valuable reconnaissance data for attackers looking for PHP-specific vulnerabilities.
Recommendation: Disable X-Powered-By headers in PHP configuration (expose_php = Off).

3. Insecure Cookie: The Set-Cookie header sets a session ID without the following security flags:
HttpOnly: Missing—allows JavaScript to access the cookie, increasing XSS attack risk
Secure: Missing—allows the cookie to be transmitted over unencrypted HTTP
SameSite: Missing—vulnerable to CSRF attacks
Recommendation: Set-Cookie: sessionid=abc123; Path=/; HttpOnly; Secure; SameSite=Strict

4. Overly Permissive Caching: Cache-Control: public allows the response to be cached by any intermediate proxy, even if the content is user-specific or sensitive. Combined with a session cookie, this could lead to session information being cached in shared proxies.
Recommendation: Use Cache-Control: private, no-store for responses containing sensitive data or cookies.

Best Practice Summary: Minimize information disclosure in headers, implement secure cookie attributes, and apply appropriate caching policies based on content sensitivity.
12
A REST API designer is deciding between using PUT or PATCH for updating user profiles. The profile contains 20 fields (name, email, phone, address, preferences, etc.). Analyze when PUT would be more appropriate than PATCH, and vice versa, considering network efficiency, data integrity, and API consistency.
Sample Answer:
When PUT is More Appropriate:

1. Complete Resource Replacement: When the client has the complete, updated representation of the resource and wants to replace the entire entity [^17^]. For example, when a user submits a complete "Edit Profile" form with all 20 fields populated.

2. Data Integrity Requirements: PUT ensures the resource is in a known, complete state after the operation. This prevents partial updates that might leave the resource in an inconsistent state if multiple fields have interdependencies.

3. Idempotency Guarantees: PUT is guaranteed to be idempotent—retrying the same request due to network timeouts produces the same result without creating side effects [^12^][^17^]. This makes PUT safer for unreliable networks.

4. Simple Implementation: Server-side logic is simpler—replace the entire resource rather than merging partial updates.

When PATCH is More Appropriate:

1. Network Efficiency: When updating only 1-2 fields out of 20, PATCH sends significantly less data (e.g., just {"email": "new@example.com"} vs. all 20 fields) [^17^]. This reduces bandwidth usage and improves performance on mobile or slow connections.

2. Concurrent Update Safety: PATCH reduces the risk of overwriting changes made by other clients. With PUT, if two clients read the resource and then PUT their updates, the second client's request overwrites the first client's changes (lost update problem). PATCH updates only specified fields, reducing collision surface.

3. Partial Update Semantics: When the client only knows what changed, not the complete current state. For example, a "Change Password" feature where only the password field is modified.

API Consistency Considerations:

Documentation Clarity: Clearly document that PUT requires the complete resource while PATCH accepts partial updates. This prevents client confusion.
Validation Differences: PUT can validate the entire resource schema, while PATCH must handle sparse validation (only validating provided fields).
Return Values: Both should return the updated resource (200 OK) or no content (204 No Content) consistently [^3^].

Recommendation: Support both methods—use PUT for full profile updates and PATCH for field-specific updates, following the JSON Merge Patch standard (application/merge-patch+json) for PATCH operations to ensure predictable behavior [^17^].