Client.js 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.rpc.Client"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.rpc.Client"] = true;
  8. dojo.provide("dojox.rpc.Client");
  9. // Provide extra headers for robust client and server communication
  10. (function() {
  11. dojo._defaultXhr = dojo.xhr;
  12. dojo.xhr = function(method,args){
  13. var headers = args.headers = args.headers || {};
  14. // set the client id, this can be used by servers to maintain state information with the
  15. // a specific client. Many servers rely on sessions for this, but sessions are shared
  16. // between tabs/windows, so this is not appropriate for application state, it
  17. // really only useful for storing user authentication
  18. headers["Client-Id"] = dojox.rpc.Client.clientId;
  19. // set the sequence id. HTTP is non-deterministic, message can arrive at the server
  20. // out of order. In complex Ajax applications, it may be more to ensure that messages
  21. // can be properly sequenced deterministically. This applies a sequency id to each
  22. // XHR request so that the server can order them.
  23. headers["Seq-Id"] = dojox._reqSeqId = (dojox._reqSeqId||0)+1;
  24. return dojo._defaultXhr.apply(dojo,arguments);
  25. }
  26. })();
  27. // initiate the client id to a good random number
  28. dojox.rpc.Client.clientId = (Math.random() + '').substring(2,14) + (new Date().getTime() + '').substring(8,13);
  29. }