I have the following code to write 304 Not Modified responses. Headers are written by various methods and passed along in the headers variable, which is used as a hash. HTTP 1.1 forbids 304 responses from returning entity headers, such as Expires. The obvious way to keep such headers out of the response is the delete operator (as shown). However, the delete operator is inefficient, and generally disreccomended for performant V8 JavaScript. Setting headers.Expires to undefined or null just sends the header as "Expires: undefined" or "Expires: null". Delete is used at most once per HTTP request, so it's probably fine, but is there a better alternative?
if ( (ifModifiedSince || ifNoneMatch) &&
(!ifModifiedSince || stats.mtime.valueOf() === ifModifiedSince) &&
(!ifNoneMatch || ifNoneMatch.indexOf(headers.ETag) >= 0) ) {
console.info("Not Modified:", interim.filePath);
// entity-headers such as Allow, Content-*, Expires, and Last-Modified are not permitted.
delete headers.Expires;
response.writeHead(304, headers);
response.end();
return;
}