source: Dev/branches/rest-dojo-ui/client/dojox/rpc/Client.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.3 KB
Line 
1define("dojox/rpc/Client", ["dojo", "dojox"], function(dojo, dojox) {
2
3        dojo.getObject("rpc.Client", true, dojox);
4
5        // Provide extra headers for robust client and server communication
6
7        dojo._defaultXhr = dojo.xhr;
8        dojo.xhr = function(method,args){
9                var headers = args.headers = args.headers || {};
10                // set the client id, this can be used by servers to maintain state information with the
11                // a specific client. Many servers rely on sessions for this, but sessions are shared
12                // between tabs/windows, so this is not appropriate for application state, it
13                // really only useful for storing user authentication
14                headers["Client-Id"] = dojox.rpc.Client.clientId;
15                // set the sequence id. HTTP is non-deterministic, message can arrive at the server
16                // out of order. In complex Ajax applications, it may be more to ensure that messages
17                // can be properly sequenced deterministically. This applies a sequency id to each
18                // XHR request so that the server can order them.
19                headers["Seq-Id"] = dojox._reqSeqId = (dojox._reqSeqId||0)+1;
20                return dojo._defaultXhr.apply(dojo,arguments);
21        }
22
23        // initiate the client id to a good random number
24        dojox.rpc.Client.clientId = (Math.random() + '').substring(2,14) + (new Date().getTime() + '').substring(8,13);
25
26        return dojox.rpc.Client;
27
28});
Note: See TracBrowser for help on using the repository browser.