How to use the statuses.redirect function in statuses

To help you get started, we’ve selected a few statuses 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 andreirtaylor / BoardGameTracking / node_modules / nodemon / node_modules / update-notifier / node_modules / latest-version / node_modules / package-json / node_modules / got / index.js View on Github external
var req = fn.request(arg, function (response) {
			var statusCode = response.statusCode;
			var res = response;

			// redirect
			if (status.redirect[statusCode] && 'location' in res.headers) {
				res.resume(); // Discard response

				if (++redirectCount > 10) {
					cb(new Error('Redirected 10 times. Aborting.'), undefined, res);
					return;
				}

				get(urlLib.resolve(url, res.headers.location), opts, cb);
				return;
			}

			if (['gzip', 'deflate'].indexOf(res.headers['content-encoding']) !== -1) {
				var unzip = zlib.createUnzip();
				res.pipe(unzip);
				res = unzip;
			}
github qiushi123 / xiaochengxu_demos / 014云开发实现小程序支付 / cloud / pay / node_modules / urllib / lib / urllib.js View on Github external
function handleRedirect(res) {
        var err = null;
        if (args.followRedirect && statuses.redirect[res.statusCode]) {  // handle redirect
            args._followRedirectCount = (args._followRedirectCount || 0) + 1;
            var location = res.headers.location;
            if (!location) {
                err = new Error('Got statusCode ' + res.statusCode + ' but cannot resolve next location from headers');
                err.name = 'FollowRedirectError';
            } else if (args._followRedirectCount > args.maxRedirects) {
                err = new Error('Exceeded maxRedirects. Probably stuck in a redirect loop ' + url);
                err.name = 'MaxRedirectError';
            } else {
                var newUrl = args.formatRedirectUrl ? args.formatRedirectUrl(url, location) : urlutil.resolve(url, location);
                debug('Request#%d %s: `redirected` from %s to %s', reqId, options.path, url, newUrl);
                // make sure timer stop
                cancelResponseTimer();
                // should clean up headers.Host on `location: http://other-domain/url`
                if (options.headers.Host && PROTO_RE.test(location)) {
                    options.headers.Host = null;
github node-modules / urllib / lib / urllib.js View on Github external
function handleRedirect(res) {
    var err = null;
    if (args.followRedirect && statuses.redirect[res.statusCode]) {  // handle redirect
      args._followRedirectCount = (args._followRedirectCount || 0) + 1;
      var location = res.headers.location;
      if (!location) {
        err = new Error('Got statusCode ' + res.statusCode + ' but cannot resolve next location from headers');
        err.name = 'FollowRedirectError';
      } else if (args._followRedirectCount > args.maxRedirects) {
        err = new Error('Exceeded maxRedirects. Probably stuck in a redirect loop ' + url);
        err.name = 'MaxRedirectError';
      } else {
        var newUrl = args.formatRedirectUrl ? args.formatRedirectUrl(url, location) : urlutil.resolve(url, location);
        debug('Request#%d %s: `redirected` from %s to %s', reqId, options.path, url, newUrl);
        // make sure timer stop
        cancelResponseTimer();
        // should clean up headers.Host on `location: http://other-domain/url`
        if (options.headers.Host && PROTO_RE.test(location)) {
          options.headers.Host = null;
github eggjs / egg-security / lib / middlewares / nosniff.js View on Github external
return async function nosniff(ctx, next) {
    await next();

    // ignore redirect response
    if (statuses.redirect[ctx.status]) return;

    const opts = utils.merge(options, ctx.securityOptions.nosniff);
    if (utils.checkIfIgnore(opts, ctx)) return;

    ctx.set('x-content-type-options', 'nosniff');
  };
};
github slashhuang / cuty / src / response.js View on Github external
redirect(url, alt) {
    // location
    if ('back' == url) url = this.ctx.get('Referrer') || alt || '/';
    this.set('Location', url);

    // status
    if (!statuses.redirect[this.status]) this.status = 302;

    // html
    if (this.ctx.accepts('html')) {
      url = escape(url);
      this.type = 'text/html; charset=utf-8';
      this.body = `Redirecting to <a href="${url}">${url}</a>.`;
      return;
    }

    // text
    this.type = 'text/plain; charset=utf-8';
    this.body = `Redirecting to ${url}.`;
  },
github thenables / requisition / lib / response.js View on Github external
function Response(req, res, options) {
  this.request = req;
  this.response = res;
  this.options = options;

  this.status =
  this.statusCode = res.statusCode;
  this.header =
  this.headers = res.headers;

  // empty the stream when the response body is irrelevant
  // because node streams are dumb like that
  var status = this.status;
  if (this.length === 0
    || statuses.empty[status]
    || statuses.redirect[status]) res.resume();
}
github toajs / toa / lib / response.js View on Github external
redirect: function (url, alt) {
    // location
    if (url === 'back') url = this.ctx.get('referrer') || alt || '/'
    this.set('location', url)

    // status
    if (!statuses.redirect[this.status]) this.status = 302

    // html
    if (this.ctx.accepts('html')) {
      url = escapeHtml(url)
      this.type = 'text/html; charset=utf-8'
      this.body = 'Redirecting to <a href="' + url + '">' + url + '</a>.'
      return
    }

    // text
    this.type = 'text/plain; charset=utf-8'
    this.body = 'Redirecting to ' + url + '.'
  },
github rill-js / rill / src / response.ts View on Github external
public redirect(url: string, alt?: string): void {
    const { req } = this.ctx;

    // Back uses request referrer header as a url.
    url = url === "back" ? (req.get("Referrer") as string) : url;
    // Default url to alternative.
    url = url || alt;

    if (!url) {
      throw new TypeError(
        "Rill#ctx.res.redirect: Cannot redirect, url not specified and alternative not provided."
      );
    }

    if (!statuses.redirect[this.status]) {
      this.status = 302;
    }

    this.set("Location", parseURL(url, req.href).href);
  }

statuses

HTTP status utility

MIT
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis