📝 HTTP protocol explained with example (46 MCQs)
HTTP's Request–Response Communication Model
HTTP organizes communication as requests from a client and responses from a server. A request identifies a target resource and expresses an intended action through its method; a response reports the outcome and may carry a representation. HTTP is stateless at the protocol level, so each request is interpreted independently unless an application uses cookies or other state mechanisms. These shared semantics let different browsers and servers interoperate reliably across different operating environments.
Methods, Targets and Header Fields
An HTTP request includes a method, request target and protocol-version information, followed by header fields and an optional body. Common methods include GET for retrieval and POST for resource-specific processing. A response contains a status code, headers and optional content. Headers describe items such as media type, content length, caching and accepted formats.
Parsing a Request and Constructing a Response
The client sends a request after establishing the required connection. The server reads the start line and fields, checks permissions and resource handling, and executes the method. It then sends a status line or equivalent protocol metadata, response fields and any content. The client interprets the status and decides whether to display, redirect or retry.
A GET Exchange for a Specific Web Resource
A browser requests /notes.html from example.net using GET. The server finds the document and returns 200 OK with Content-Type: text/html and the HTML bytes. If the path is unavailable, it can instead return 404 Not Found. The differing status values describe the processing result, not the physical condition of the network.
Status Codes and Representation Metadata
HTTP methods describe application intent, while TCP or QUIC carries data between endpoints. A Content-Type field describes the representation format, whereas Content-Length describes a message content length when applicable. Redirect responses can direct the client to another URI, and cache-control fields influence whether an intermediary may reuse a stored response.
Frequent Errors in Reading HTTP Examples
'GET always changes server data' is incorrect because GET is defined as a retrieval method and should not request a state change. 'POST is the only method with a body' is false because other methods can carry content. '200 means the page is visually correct' is wrong because it reports protocol-level success, not whether the returned content meets the user's needs.
Analyzing HTTP Requests and Response Codes
Practice identifying the request line, target, method, headers, optional body, response status and response content. Recognize 200 as success, 301 or 302 as redirection, 400 as a client error, 404 as not found and 500 as a server error. Check that explanations distinguish protocol outcome from browser rendering and application logic.
HTTP Message and Response Terms
- Request - Asks a server to perform an operation.
- Response - Reports processing results to a client.
- GET - Retrieves a current resource representation.
- Status code - Indicates the result of a request.
- Content-Type - Identifies the returned media format.
- Header - Carries message metadata.
📝 All HTTP protocol explained with example MCQs
Q1. In a client‑server interaction, if a client repeatedly sends malformed requests causing the server to close the connection, what is the most likely cause of this behavior?
📖 Explanation: The server monitors request syntax and, upon detecting malformed or suspicious requests, often closes the connection to protect resources. This defensive behavior is typical when the server identifies a potential security threat, such as injection attempts, rather than issues like unsupported methods or DNS failures.
Q2. A web application uses both GET and POST methods for the same resource. Which reasoning best explains why this might be problematic for caching mechanisms?
📖 Explanation: Caching proxies generally differentiate based on method; GET is cache‑friendly, while POST is intended for state‑changing operations. When both methods are used for the same URI, caches may store inconsistent representations, leading to stale or duplicate data, because they cannot reliably decide which representation reflects the latest state.
Q3. If a server implements HTTP/2 multiplexing, what inference can be drawn about its handling of head‑of‑line blocking compared to HTTP/1.1?
📖 Explanation: HTTP/2’s multiplexing allows multiple streams to coexist on one TCP connection, so a blocked or delayed stream does not stall others. This design directly addresses the head‑of‑line blocking problem present in HTTP/1.1, where each request‑response pair occupies its own connection, causing delays if one stream stalls.
Q4. Consider a scenario where a client uses persistent connections but the server closes the socket after each response. Which logical deduction explains the mismatch?
📖 Explanation: Middleboxes such as proxies or firewalls sometimes remove or alter the Connection header, causing the server to believe the client does not request persistence. Consequently, the server closes the socket after each response, even though the client originally indicated a desire for a persistent connection.
Q5. A developer claims that adding more request headers will always improve security. Which analytical assessment best refutes this claim?
📖 Explanation: While headers can convey security directives (e.g., CSP, HSTS), adding many unnecessary headers may leak information about server configuration, software versions, or internal policies. This exposure can aid attackers in fingerprinting the system, thereby reducing overall security rather than enhancing it.
Q6. When comparing HTTP status codes 301 and 302, which conceptual difference is most accurate regarding client behavior?
📖 Explanation: A 301 (Moved Permanently) signals that the resource has a new permanent URI, prompting clients to update bookmarks and cache the new location. A 302 (Found) is temporary; clients may repeat the request at the original URI later, and the method may change (often to GET), reflecting the transient nature of the redirect.
Q7. If an HTTP response includes both Cache‑Control: no-store and ETag headers, what is the most logical effect on caching behavior?
📖 Explanation: Cache‑Control: no-store explicitly instructs caches not to retain the response. Consequently, any ETag present cannot be used for subsequent cache validation because the response is never stored. The ETag may still be useful for conditional requests to the origin server, but it does not affect caching.
Q8. A web service returns a JSON payload with a Content‑Type of text/html. Which inference best explains the potential client‑side issue?
📖 Explanation: When the Content‑Type header does not match the actual payload format, clients rely on the declared type. Declaring text/html for JSON leads browsers or libraries to attempt HTML parsing, resulting in errors or ignored data, whereas the correct application/json type would enable proper JSON deserialization.
Q9. Suppose a client sends a request with the Expect: 100‑continue header but never receives the interim 100 response. Which logical conclusion is most plausible?
📖 Explanation: When a server does not wish to process the request body, it can immediately send a final status (e.g., 4xx) without the interim 100 Continue. This behavior indicates the server’s decision to reject or ignore the request, rather than a network issue or client error.
Q10. In a RESTful API design, which analytical comparison best illustrates the advantage of using HTTP verbs over RPC‑style endpoints?
📖 Explanation: REST leverages HTTP verbs (GET, POST, PUT, DELETE) to represent Create, Read, Update, Delete actions uniformly across resources. This uniform interface simplifies client logic, enhances cacheability, and aligns with web standards, whereas RPC endpoints often embed action names in URLs, breaking the uniformity principle.
Q11. A CDN edge server returns a stale object after the origin server has updated the resource. Which conceptual reason most likely explains this behavior?
📖 Explanation: CDNs honor the Time‑to‑Live (TTL) value set by the origin. Until the TTL expires, the edge server serves the cached copy, even if the origin has newer content. This design reduces load on the origin and improves latency, but can temporarily serve stale data.
Q12. If a client repeatedly receives HTTP 429 responses, what deduction can be made about the server’s policy?
📖 Explanation: HTTP 429 (Too Many Requests) explicitly indicates that the client has sent too many requests in a given time window, triggering the server’s rate‑limiting mechanism. It is not related to internal errors, network congestion, or certificate issues.
Q13. When analyzing logs, a pattern shows that GET requests to /api/data always return 200, but POST requests to the same endpoint return 405. Which analytical explanation best fits?
📖 Explanation: A 405 Method Not Allowed response indicates that the HTTP method is not supported for the targeted resource. If GET succeeds but POST fails consistently, the endpoint is likely designed as read‑only, intentionally rejecting POST operations.
Q14. A client sends an HTTP request with both Transfer‑Encoding: chunked and Content‑Length headers. Which logical reasoning best describes the server’s expected handling?
📖 Explanation: According to RFC 7230, when Transfer‑Encoding is present, the server must ignore any Content‑Length header because chunked encoding defines the message length. The presence of both headers is not an error; the server processes the message using the chunked transfer method.
Q15. If an HTTP response includes the header Strict‑Transport‑Security: max‑age=31536000; includeSubDomains, which conceptual impact does this have on future client requests?
📖 Explanation: The Strict‑Transport‑Security (HSTS) header instructs compliant browsers to automatically use HTTPS for the originating domain and all its subdomains for the duration specified by max‑age (here, one year). This prevents downgrade attacks and ensures secure connections for future requests.
Q16. Which factual recall question correctly identifies the default port for HTTPS?
📖 Explanation: HTTPS, the secure version of HTTP, uses TCP port 443 by default, whereas plain HTTP uses port 80. This is a standard convention defined by the IANA.
Q17. What is the primary purpose of the HTTP OPTIONS method?
📖 Explanation: The OPTIONS method asks the server which HTTP methods and other capabilities are supported for a given resource, allowing clients to discover allowed actions without performing them.
Q18. Which factual recall question correctly defines the meaning of the HTTP status code 404?
📖 Explanation: The 404 status code indicates that the server cannot find the requested resource. It is a client‑side error meaning the URI does not map to any existing content.
Q19. In HTTP/1.1, which header is used to indicate that a connection should be closed after the current request/response cycle?
📖 Explanation: The Connection header with the value close tells the server to close the TCP connection after completing the current request/response, overriding the default persistent connection behavior of HTTP/1.1.
Q20. A client receives an HTTP 301 response with a Location header pointing to a new URL that uses the same scheme. Which logical deduction about caching is most accurate?
📖 Explanation: A 301 Moved Permanently response tells clients that the resource has a new permanent URI. Clients typically update their caches and future requests to use the new URL, treating it as the canonical location for the resource.
Q21. When comparing HTTP/1.1 pipelining with HTTP/2 multiplexing, which analytical distinction best captures their performance differences?
📖 Explanation: HTTP/1.1 pipelining sends multiple requests without waiting for responses, but the server must reply in order, causing head‑of‑line blocking if an early response is delayed. HTTP/2 multiplexing sends frames from many streams concurrently, eliminating this blockage and improving overall throughput.
Q22. If an API returns a 202 Accepted status after receiving a POST request, what conceptual implication does this have for the client?
📖 Explanation: A 202 status indicates that the server has accepted the request for processing, but the processing is not yet finished. The client may need to poll or be notified later to determine the final outcome.
Q23. A server sends the header Vary: Accept-Encoding. Which analytical conclusion about caching can be drawn?
📖 Explanation: The Vary header tells caches that the response varies based on the specified request header(s). With Accept-Encoding, caches must keep distinct versions for gzip, deflate, etc., ensuring the client receives the appropriate encoding.
Q24. When a client includes the header If-None-Match with an ETag value, which conceptual behavior does the server exhibit if the resource has not changed?
📖 Explanation: If-None-Match contains an ETag that matches the current version of the resource, the server responds with 304 Not Modified, indicating the client can use its cached copy and no message body is sent.
Q25. Which logical reasoning best explains why a proxy might transform an HTTP request from HTTP/1.1 to HTTP/0.9?
📖 Explanation: Proxies sometimes downgrade the protocol version to reduce overhead, especially in low‑bandwidth environments. By sending an HTTP/0.9 request, which lacks headers, the proxy can minimize the amount of data transmitted, though this sacrifices functionality.
Q26. If a client receives a 401 Unauthorized response without a WWW‑Authenticate header, what deduction can be made about the server’s compliance?
📖 Explanation: RFC 7235 requires a WWW‑Authenticate header in a 401 response to indicate the authentication scheme required. Its absence means the server is not adhering to the standard, leading to ambiguous client behavior.
Q27. A web application uses HTTP Basic authentication over an unencrypted connection. Which analytical assessment most accurately describes the security risk?
📖 Explanation: HTTP Basic authentication transmits the user name and password encoded in Base64, which is not encryption. Over an unencrypted channel, anyone able to sniff traffic can decode and obtain the credentials, representing a serious security vulnerability.
Q28. When comparing cookie attributes, which conceptual difference best distinguishes Secure from HttpOnly?
📖 Explanation: The Secure attribute tells browsers to send the cookie only over secure (HTTPS) connections, protecting it from network eavesdropping. HttpOnly prevents client‑side scripts (e.g., JavaScript) from accessing the cookie, mitigating cross‑site scripting attacks. They address different threat vectors.
Q29. If a server includes the header Content‑Security‑Policy: default-src 'self'; script-src 'none', which conceptual effect does this have on page behavior?
📖 Explanation: The CSP directive script-src 'none' disallows all script execution, while default-src 'self' limits other resource types (e.g., images, styles) to the same origin. Together, this policy blocks any JavaScript from running, enhancing security against XSS attacks.
Q30. A client sends a request with a malformed Host header. Which logical deduction explains the server’s likely response?
📖 Explanation: A malformed Host header violates HTTP/1.1 requirements, prompting the server to reject the request with a 400 Bad Request status, indicating that the request cannot be understood due to syntactic errors.
Q31. Which factual recall question correctly identifies the purpose of the HTTP CONNECT method?
📖 Explanation: The CONNECT method is used by clients to establish a network tunnel, typically for SSL/TLS through an HTTP proxy, allowing a direct TCP connection to the target server.
Q32. When an HTTP response includes both Expires and Cache‑Control: max‑age directives, which analytical rule determines the effective freshness lifetime?
📖 Explanation: According to RFC 7234, the Cache‑Control max‑age directive overrides the Expires header when both are present, providing a more explicit freshness lifetime that the client must follow.
Q33. If a client receives an HTTP 307 Temporary Redirect, which conceptual behavior must it follow regarding the request method?
📖 Explanation: A 307 response indicates that the resource resides temporarily under a different URI, but the client must repeat the request using the same HTTP method and request body, unlike a 302 which may switch to GET.
Q34. A developer argues that using HTTP/1.0 with the Connection: keep‑alive header provides the same performance as HTTP/2. Which analytical critique best challenges this view?
📖 Explanation: While adding Connection: keep‑alive to HTTP/1.0 reduces connection overhead, it still lacks HTTP/2’s multiplexing (allowing multiple concurrent streams), header compression (HPACK), and binary framing, all of which significantly improve performance beyond simple keep‑alive.
Q35. When a client includes the Accept header with values text/html, application/json;q=0.8, what conceptual effect does the quality factor have?
📖 Explanation: The quality factor (q) assigns a relative weight to each media type. A higher value (default 1.0) for text/html means the client prefers HTML, while a lower q=0.8 for JSON indicates lower preference, guiding the server’s content negotiation.
Q36. If a server sends a Set‑Cookie header with the attribute SameSite=Strict, which logical outcome best describes subsequent cross‑site requests?
📖 Explanation: SameSite=Strict instructs browsers to include the cookie only when the request originates from the same site as the cookie’s domain. Any cross‑site request, even user‑initiated, will not carry the cookie, mitigating CSRF attacks.
Q37. A REST API returns a 409 Conflict response when a client attempts to create a resource that already exists. Which analytical explanation best reflects the semantics of this status code?
📖 Explanation: A 409 Conflict indicates that the request could not be completed because it would cause a conflict with the existing state of the resource, such as attempting to create a duplicate entity. This informs the client to resolve the conflict before retrying.
Q38. Which factual recall question correctly states the default HTTP version used by modern browsers when establishing a new connection?
📖 Explanation: Modern browsers negotiate HTTP/2 (or higher) over TLS when both ends support it, but the baseline default without negotiation is HTTP/1.1. However, the question asks for the default version used when establishing a new connection, which is typically HTTP/2 if available. The correct answer is HTTP/2.0.
Q39. When a server includes both Pragma: no‑cache and Cache‑Control: max‑age=3600 in a response, which analytical reasoning explains the effective caching behavior?
📖 Explanation: Cache‑Control is the modern directive and overrides the legacy Pragma header. Therefore, despite Pragma: no‑cache, the response can be cached for the duration specified by max‑age (3600 seconds).
Q40. If a client sends a request with Transfer‑Encoding: chunked but the server does not support chunked encoding, what logical outcome is most likely?
📖 Explanation: When a server does not understand the Transfer‑Encoding header, it should respond with 501 Not Implemented, indicating that the functionality required to process the request is not supported.
Q41. A web service uses HTTP/1.1 persistent connections but experiences high latency due to many small requests. Which conceptual improvement would most effectively reduce latency?
📖 Explanation: HTTP/2 multiplexing allows multiple requests to be sent concurrently over a single connection, eliminating the need for sequential request/response cycles that cause latency in HTTP/1.1 when many small requests are made.
Q42. When a client receives an HTTP 500 Internal Server Error, which logical inference about the server’s state is most appropriate?
📖 Explanation: A 500 status code signals that the server encountered an unexpected condition (e.g., unhandled exception) that prevented it from fulfilling the request. It does not imply client‑side errors such as malformed requests, missing resources, or authorization issues.
Q43. If an HTTP response contains the header X-Frame-Options: DENY, which conceptual effect does this have on the page?
📖 Explanation: X-Frame-Options: DENY instructs browsers to prevent the page from being displayed inside any frame or iframe, protecting against clickjacking attacks by disallowing embedding regardless of the embedding page’s origin.
Q44. A client uses the HEAD method to request a resource. Which analytical statement correctly describes the server’s expected response?
📖 Explanation: The HEAD method is identical to GET except that the server must not include a message body in the response. It returns the status line and headers, allowing the client to inspect metadata (e.g., Content‑Length) without transferring the full content.
Q45. When evaluating the impact of HTTP pipelining, which logical reasoning explains why it might not improve performance on high‑latency networks?
📖 Explanation: Even though pipelining allows sending multiple requests without waiting for responses, the server must still send replies in order. If an early response is delayed, subsequent responses are blocked, negating the potential latency benefits, especially on high‑latency links.
Q46. A developer claims that setting Cache‑Control: public on a response automatically makes it cacheable by all intermediaries. Which analytical counter‑argument best refutes this claim?
📖 Explanation: Cache‑Control: public indicates that the response may be stored by any cache, but other directives (e.g., no‑store, private) can override this permission. Intermediaries must respect the most restrictive applicable directive, so simply adding public does not guarantee caching if conflicting headers exist.