How to use vary - 6 common examples

To help you get started, we’ve selected a few vary 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 fastify / fastify-cors / index.js View on Github external
function vary (reply, field) {
  var value = reply.getHeader('Vary') || ''
  var header = Array.isArray(value)
    ? value.join(', ')
    : String(value)

  // set new header
  if ((value = append(header, field))) {
    reply.header('Vary', value)
  }
}
github koajs / cors / index.js View on Github external
if (options.credentials === true) {
        set('Access-Control-Allow-Credentials', 'true');
      }

      if (options.exposeHeaders) {
        set('Access-Control-Expose-Headers', options.exposeHeaders);
      }

      if (!options.keepHeadersOnError) {
        return await next();
      }
      try {
        return await next();
      } catch (err) {
        const errHeadersSet = err.headers || {};
        const varyWithOrigin = vary.append(errHeadersSet.vary || errHeadersSet.Vary || '', 'Origin');
        delete errHeadersSet.Vary;

        err.headers = Object.assign({}, errHeadersSet, headersSet, { vary: varyWithOrigin });

        throw err;
      }
    } else {
      // Preflight Request

      // If there is no Access-Control-Request-Method header or if parsing failed,
      // do not set any additional headers and terminate this set of steps.
      // The request is outside the scope of this specification.
      if (!ctx.get('Access-Control-Request-Method')) {
        // this not preflight request, ignore it
        return await next();
      }
github trekjs / trek / lib / response.js View on Github external
vary (field) {
    vary(this.res, field)
  }
github ethanresnick / json-api / src / http-strategies / Koa.ts View on Github external
protected sendResources(responseObject, ctx): void | true {
    const { vary, ...otherHeaders } = responseObject.headers;

    if(vary) {
      varyLib(ctx.res, vary);
    }

    if(responseObject.status === 406 && !this.config.handleContentNegotiation) {
      return true;
    }

    ctx.status(responseObject.status || 200);

    Object.keys(otherHeaders).forEach(k => {
      ctx.res.set(k, otherHeaders[k]);
    });

    if(responseObject.body !== undefined) {
      ctx.body = new Buffer(responseObject.body);
    }
  }
github ehmicky / autoserver / src / protocols / adapters / http / send / headers.js View on Github external
const setVary = function({ res, type }) {
  const objectVary = isType(type, 'object') ? OBJECT_VARY_HEADERS : []
  vary(res, [...objectVary, ...VARY_HEADERS])
}
github ethanresnick / json-api / build / src / http-strategies / Koa.js View on Github external
sendResources(responseObject, ctx) {
        const _a = responseObject.headers, { vary } = _a, otherHeaders = __rest(_a, ["vary"]);
        if (vary) {
            vary_1.default(ctx.res, vary);
        }
        if (responseObject.status === 406 && !this.config.handleContentNegotiation) {
            return true;
        }
        ctx.status(responseObject.status || 200);
        Object.keys(otherHeaders).forEach(k => {
            ctx.res.set(k, otherHeaders[k]);
        });
        if (responseObject.body !== undefined) {
            ctx.body = new Buffer(responseObject.body);
        }
    }
    sendError(errors, ctx) {

vary

Manipulate the HTTP Vary header

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis

Popular vary functions