B2G/gecko/services/common/modules-testing/storageserver.js
/**
   * Handler for PUT requests for this BSO.
   */
Handler for PUT requests for this BSO.
Handler for PUT requests for this BSO .
function putHandler(request, response) {
    if (request.hasHeader("Content-Type")) {
      let ct = request.getHeader("Content-Type");
      if (ct != "application/json") {
        throw HTTP_415;
      }
    }
    let input = CommonUtils.readBytesFromInputStream(request.bodyInputStream);
    let parsed;
    try {
      parsed = JSON.parse(input);
    } catch (ex) {
      return sendMozSvcError(request, response, "8");
    }
    if (typeof(parsed) != "object") {
      return sendMozSvcError(request, response, "8");
    }
    if (request.hasHeader("x-if-unmodified-since")) {
      let reqModified = parseInt(request.getHeader("x-if-unmodified-since"));
      if (reqModified < this.modified) {
        response.setStatusLine(request.httpVersion, 412, "Precondition Failed");
        return;
      }
    }
    let code, status;
    if (this.payload) {
      code = 204;
      status = "No Content";
    } else {
      code = 201;
      status = "Created";
    }
    for (let [key, value] in Iterator(parsed)) {
      switch (key) {
        case "payload":
          if (typeof(value) != "string") {
            sendMozSvcError(request, response, "8");
            return true;
          }
          this.payload = value;
          break;
        case "ttl":
          if (!isInteger(value)) {
            sendMozSvcError(request, response, "8");
            return true;
          }
          this.ttl = parseInt(value, 10);
          break;
        case "sortindex":
          if (!isInteger(value) || value.length > 9) {
            sendMozSvcError(request, response, "8");
            return true;
          }
          this.sortindex = parseInt(value, 10);
          break;
        case "id":
          break;
        default:
          this._log.warn("Unexpected field in BSO record: " + key);
          sendMozSvcError(request, response, "8");
          return true;
      }
    }
    this.modified = request.timestamp;
    response.setHeader("X-Last-Modified", "" + this.modified, false);
    response.setStatusLine(request.httpVersion, code, status);
  }
function putHandler ( request , response ) { if ( request . hasHeader ( "Content-Type" ) ) { let ct = request . getHeader ( "Content-Type" ) ; if ( ct != "application/json" ) { throw HTTP_415 ; } } let input = CommonUtils . readBytesFromInputStream ( request . bodyInputStream ) ; let parsed ; try { parsed = JSON . parse ( input ) ; } catch ( ex ) { return sendMozSvcError ( request , response , "8" ) ; } if ( typeof ( parsed ) != "object" ) { return sendMozSvcError ( request , response , "8" ) ; } if ( request . hasHeader ( "x-if-unmodified-since" ) ) { let reqModified = parseInt ( request . getHeader ( "x-if-unmodified-since" ) ) ; if ( reqModified < this . modified ) { response . setStatusLine ( request . httpVersion , 412 , "Precondition Failed" ) ; return ; } } let code , status ; if ( this . payload ) { code = 204 ; status = "No Content" ; } else { code = 201 ; status = "Created" ; } for ( let [ key , value ] in Iterator ( parsed ) ) { switch ( key ) { case "payload" : if ( typeof ( value ) != "string" ) { sendMozSvcError ( request , response , "8" ) ; return true ; } this . payload = value ; break ; case "ttl" : if ( ! isInteger ( value ) ) { sendMozSvcError ( request , response , "8" ) ; return true ; } this . ttl = parseInt ( value , 10 ) ; break ; case "sortindex" : if ( ! isInteger ( value ) || value . length > 9 ) { sendMozSvcError ( request , response , "8" ) ; return true ; } this . sortindex = parseInt ( value , 10 ) ; break ; case "id" : break ; default : this . _log . warn ( "Unexpected field in BSO record: " + key ) ; sendMozSvcError ( request , response , "8" ) ; return true ; } } this . modified = request . timestamp ; response . setHeader ( "X-Last-Modified" , "" + this . modified , false ) ; response . setStatusLine ( request . httpVersion , code , status ) ; }
Handler for PUT requests for this BSO.
Handler for PUT requests for this BSO .
// Don't update if a conditional request fails preconditions. // Alert when we see unrecognized fields.