Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.stat(fileStream.path, (error, filestats) => {
if (error) {
this.log(`Error receiving file statistics: ${String(error)}`)
return sendRequestResult()
}
// push the ETag header to the response
const fileEtag = etag(filestats, { weak: true })
connection.rawConnection.responseHeaders.push([ 'ETag', fileEtag ])
let noneMatchHeader = reqHeaders[ 'if-none-match' ]
let cacheCtrlHeader = reqHeaders[ 'cache-control' ]
let noCache = false
let etagMatches
// check for no-cache cache request directive
if (cacheCtrlHeader && cacheCtrlHeader.indexOf('no-cache') !== -1) { noCache = true }
// parse if-none-match
if (noneMatchHeader) { noneMatchHeader = noneMatchHeader.split(/ *, */) }
// if-none-match
if (noneMatchHeader) {
etagMatches = noneMatchHeader.some(match => match === '*' || match === fileEtag || match === 'W/' + fileEtag)
export function sendHTML (req, res, html, method, { dev, generateEtags }) {
if (isResSent(res)) return
const etag = generateEtags && generateETag(html)
if (fresh(req.headers, { etag })) {
res.statusCode = 304
res.end()
return
}
if (dev) {
// In dev, we should not cache pages for any reason.
// That's why we do this.
res.setHeader('Cache-Control', 'no-store, must-revalidate')
}
if (etag) {
res.setHeader('ETag', etag)
}
export function sendHTML(req, res, html, method, { dev }) {
if (res.finished) return;
const etag = generateETag(html);
if (fresh(req.headers, { etag })) {
res.statusCode = 304;
res.end();
return;
}
if (dev) {
// In dev, we should not cache pages for any reason.
// That's why we do this.
res.setHeader('Cache-Control', 'no-store, must-revalidate');
}
res.setHeader('ETag', etag);
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', Buffer.byteLength(html));
export function newEtag(): string {
return etag(`${new Date().getTime()}`);
}
public sendHTML(
req: IncomingMessage,
res: ServerResponse,
html: string,
method: string
) {
if (isResSent(res)) return
const { dev, generateEtags } = config.get()
const etag = generateEtags && generateETag(html)
if (fresh(req.headers, { etag })) {
res.statusCode = 304
res.end()
return
}
if (dev) {
res.setHeader('Cache-Control', 'no-store, must-revalidate')
}
if (etag) {
res.setHeader('ETag', etag)
}
if (!res.getHeader('Content-Type')) {
res.setHeader('Content-Type', 'text/html; charset=utf-8')
}
res.setHeader('Content-Length', Buffer.byteLength(html))
export function sendHTML(
req: IncomingMessage,
res: ServerResponse,
html: string,
{
generateEtags,
poweredByHeader,
}: { generateEtags: boolean; poweredByHeader: boolean }
) {
if (isResSent(res)) return
const etag = generateEtags ? generateETag(html) : undefined
if (poweredByHeader) {
res.setHeader('X-Powered-By', 'Next.js')
}
if (fresh(req.headers, { etag })) {
res.statusCode = 304
res.end()
return
}
if (etag) {
res.setHeader('ETag', etag)
}
if (!res.getHeader('Content-Type')) {
export function newEtag(): string {
return etag(`${new Date().getTime()}`);
}