Complete the code to set an ETag header in the response.
res.setHeader('ETag', [1]);
The ETag header should be set to a unique value representing the resource version, here 'etagValue'.
Complete the code to check if the client's ETag matches the server's ETag.
if (req.headers['if-none-match'] === [1]) {
The 'If-None-Match' header contains the client's ETag. We compare it to the server's current ETag value.
Fix the error in the code to send a 304 Not Modified response when ETags match.
if (req.headers['if-none-match'] === [1]) { res.statusCode = 304; res.end(); }
The server must compare the client's 'If-None-Match' header to the current ETag value, here 'etagValue'.
Fill both blanks to generate an ETag from the response body and set it in the header.
const crypto = require('crypto'); const etag = crypto.createHash('[1]').update(body).digest('[2]'); res.setHeader('ETag', etag);
ETags are often generated using a hash like MD5, and the digest is commonly in hex format.
Fill all three blanks to handle conditional GET requests with ETag validation.
const etag = generateETag(body); res.setHeader('ETag', [1]); if (req.headers['if-none-match'] === [2]) { res.statusCode = [3]; res.end(); }
The ETag header is set to 'etag'. The request's 'If-None-Match' is compared to 'etag'. If they match, respond with 304 Not Modified.