An ETag is a unique identifier assigned to a specific version of a resource. It helps clients and servers determine if the resource has changed, enabling efficient caching and conditional requests.
If the ETag matches, the server knows the client has the latest version and responds with 304 Not Modified, saving bandwidth by not sending the body again.
const http = require('http'); const resource = 'Hello World'; const etag = '"12345"'; // example ETag http.createServer((req, res) => { // Your code here }).listen(3000);
Option B correctly sets the ETag header, checks if the client's If-None-Match matches the ETag, and responds with 304 if it does, otherwise sends the resource with 200.
The code sets statusCode to 304 inside the if block but then immediately overwrites it to 200 before sending the response, so the client always receives 200 with the full body.
Since the If-None-Match header value "v2" does not match the current ETag "v1", the server responds with 200 OK and sends the resource body.