B2G/gecko/services/aitc/modules/client.js
// Set values from X-Backoff and Retry-After headers, if present.
Set values from X-Backoff and Retry-After headers, if present.
Set values from X - Backoff and Retry - After headers if present .
function _setBackoff(req) {
    let backoff = 0;
    let statusCodesWithoutBackoff = [200, 201, 204, 304, 401];
    let val;
    if (req.response.headers["Retry-After"]) {
      val = req.response.headers["Retry-After"];
      backoff = parseInt(val, 10);
      this._log.warn("Retry-Header header was seen: " + val);
    } else if (req.response.headers["X-Backoff"]) {
      val = req.response.headers["X-Backoff"];
      backoff = parseInt(val, 10);
      this._log.warn("X-Backoff header was seen: " + val);
    } else if (statusCodesWithoutBackoff.indexOf(req.response.status) === -1) {
      this._consecutiveFailures++;
      if (this._consecutiveFailures === this._maxFailures) {
        backoff = this._state.get("backoff.initial", DEFAULT_INITIAL_BACKOFF);
      } else if (this._consecutiveFailures > this._maxFailures) {
        backoff = Math.min(
          this._backoffTime * 2,
          this._state.get("backoff.max", DEFAULT_MAX_BACKOFF)
        );
      }
    } else {
      this._consecutiveFailures = 0;
    }
    if (backoff) {
      this._backoff = true;
      let time = Date.now();
      this._state.set("backoff", "" + (time + backoff));
      this._backoffTime = backoff;
      this._log.info("Client setting backoff to: " + backoff + "ms");
    }
  }
function _setBackoff ( req ) { let backoff = 0 ; let statusCodesWithoutBackoff = [ 200 , 201 , 204 , 304 , 401 ] ; let val ; if ( req . response . headers [ "Retry-After" ] ) { val = req . response . headers [ "Retry-After" ] ; backoff = parseInt ( val , 10 ) ; this . _log . warn ( "Retry-Header header was seen: " + val ) ; } else if ( req . response . headers [ "X-Backoff" ] ) { val = req . response . headers [ "X-Backoff" ] ; backoff = parseInt ( val , 10 ) ; this . _log . warn ( "X-Backoff header was seen: " + val ) ; } else if ( statusCodesWithoutBackoff . indexOf ( req . response . status ) === - 1 ) { this . _consecutiveFailures ++ ; if ( this . _consecutiveFailures === this . _maxFailures ) { backoff = this . _state . get ( "backoff.initial" , DEFAULT_INITIAL_BACKOFF ) ; } else if ( this . _consecutiveFailures > this . _maxFailures ) { backoff = Math . min ( this . _backoffTime * 2 , this . _state . get ( "backoff.max" , DEFAULT_MAX_BACKOFF ) ) ; } } else { this . _consecutiveFailures = 0 ; } if ( backoff ) { this . _backoff = true ; let time = Date . now ( ) ; this . _state . set ( "backoff" , "" + ( time + backoff ) ) ; this . _backoffTime = backoff ; this . _log . info ( "Client setting backoff to: " + backoff + "ms" ) ; } }
Set values from X-Backoff and Retry-After headers, if present.
Set values from X - Backoff and Retry - After headers if present .
// Bad status code. // Initialize the backoff. // Set the backoff to the smallest of either: // double the current backoff // or the max backoff. // Good Status Code.