B2G/gecko/services/common/modules-testing/aitcserver.js
/**
   * HTTP handler for requests for a specific user.
   *
   * This handles request routing to the appropriate handler.
   */
HTTP handler for requests for a specific user.
This handles request routing to the appropriate handler.
HTTP handler for requests for a specific user . This handles request routing to the appropriate handler .
function _userHandler(username, request, response) {
    if (this.mockStatus.code && this.mockStatus.method) {
      this._respondWithMockStatus(request, response);
      return;
    }
    this._onRequest();
    this._log.info("Request: " + request.method + " " + request.path);
    let path = request.path;
    let prefix = this.VERSION_PATH + username + "/";
    if (path.indexOf(prefix) != 0) {
      throw new Error("userHandler invoked improperly.");
    }
    let user = this.users[username];
    if (!user) {
      throw new Error("User handler should not have been invoked for an " +
                      "unknown user!");
    }
    let requestTime = Date.now();
    response.dispatchTime = requestTime;
    response.setHeader("X-Timestamp", "" + requestTime);
    let handler;
    let remaining = path.substr(prefix.length);
    if (remaining == "apps" || remaining == "apps/") {
      this._log.info("Dispatching to apps index handler.");
      handler = this._appsIndexHandler.bind(this, user, request, response);
    } else if (!remaining.indexOf("apps/")) {
      let id = remaining.substr("apps/".length);
      this._log.info("Dispatching to app handler.");
      handler = this._appsAppHandler.bind(this, user, id, request, response);
    } else if (remaining == "devices" || !remaining.indexOf("devices/")) {
      this._log.info("Dispatching to devices handler.");
      handler = this._devicesHandler.bind(this, user,
                                          remaining.substr("devices".length),
                                          request, response);
    } else {
      throw HTTP_404;
    }
    try {
      handler();
    } catch (ex) {
      if (ex instanceof HttpError) {
        response.setStatusLine(request.httpVersion, ex.code, ex.description);
        return;
      }
      this._log.warn("Exception when processing request: " +
                     CommonUtils.exceptionStr(ex));
      throw ex;
    }
  }
function _userHandler ( username , request , response ) { if ( this . mockStatus . code && this . mockStatus . method ) { this . _respondWithMockStatus ( request , response ) ; return ; } this . _onRequest ( ) ; this . _log . info ( "Request: " + request . method + " " + request . path ) ; let path = request . path ; let prefix = this . VERSION_PATH + username + "/" ; if ( path . indexOf ( prefix ) != 0 ) { throw new Error ( "userHandler invoked improperly." ) ; } let user = this . users [ username ] ; if ( ! user ) { throw new Error ( "User handler should not have been invoked for an " + "unknown user!" ) ; } let requestTime = Date . now ( ) ; response . dispatchTime = requestTime ; response . setHeader ( "X-Timestamp" , "" + requestTime ) ; let handler ; let remaining = path . substr ( prefix . length ) ; if ( remaining == "apps" || remaining == "apps/" ) { this . _log . info ( "Dispatching to apps index handler." ) ; handler = this . _appsIndexHandler . bind ( this , user , request , response ) ; } else if ( ! remaining . indexOf ( "apps/" ) ) { let id = remaining . substr ( "apps/" . length ) ; this . _log . info ( "Dispatching to app handler." ) ; handler = this . _appsAppHandler . bind ( this , user , id , request , response ) ; } else if ( remaining == "devices" || ! remaining . indexOf ( "devices/" ) ) { this . _log . info ( "Dispatching to devices handler." ) ; handler = this . _devicesHandler . bind ( this , user , remaining . substr ( "devices" . length ) , request , response ) ; } else { throw HTTP_404 ; } try { handler ( ) ; } catch ( ex ) { if ( ex instanceof HttpError ) { response . setStatusLine ( request . httpVersion , ex . code , ex . description ) ; return ; } this . _log . warn ( "Exception when processing request: " + CommonUtils . exceptionStr ( ex ) ) ; throw ex ; } }
HTTP handler for requests for a specific user.
HTTP handler for requests for a specific user .