How to use etag - 7 common examples

To help you get started, we’ve selected a few etag examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StellarFw / stellar / src / servers / web.js View on Github external
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)
github lnlfps / symph-joy / server / render.js View on Github external
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)
  }
github avetjs / avet / core / server / render.js View on Github external
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));
github Azure / Azurite / src / queue / utils / utils.ts View on Github external
export function newEtag(): string {
  return etag(`${new Date().getTime()}`);
}
github TaumuLu / lissom / src / server / index.ts View on Github external
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))
github zeit / next.js / packages / next / next-server / server / send-html.ts View on Github external
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')) {
github Azure / Azurite / src / utils.ts View on Github external
export function newEtag(): string {
  return etag(`${new Date().getTime()}`);
}

etag

Create simple HTTP ETags

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis

Popular etag functions