source: Dev/trunk/src/client/dojox/io/xhrWindowNamePlugin.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.0 KB
Line 
1define([
2        "dojo/_base/kernel",
3        "dojo/_base/json",
4        "dojo/_base/xhr",
5        "dojox/io/xhrPlugins",
6        "dojox/io/windowName",
7        "dojox/io/httpParse",
8        "dojox/secure/capability"
9], function(dojo, json, xhr, xhrPlugins, windowName, httpParse, capability){
10dojo.getObject("io.xhrWindowNamePlugin", true, dojox);
11
12dojox.io.xhrWindowNamePlugin = function(/*String*/url, /*Function?*/httpAdapter, /*Boolean?*/trusted){
13        // summary:
14        //              Adds the windowName transport as an XHR plugin for the given site. See
15        //              dojox.io.windowName for more information on the transport.
16        // url:
17        //              Url prefix of the site which can handle windowName requests.
18        // httpAdapter:
19        //              This allows for adapting HTTP requests that could not otherwise be
20        //              sent with window.name, so you can use a convention for headers and PUT/DELETE methods.
21        xhrPlugins.register(
22                "windowName",
23                function(method,args){
24                         return args.sync !== true &&
25                                (method == "GET" || method == "POST" || httpAdapter) &&
26                                (args.url.substring(0,url.length) == url);
27                },
28                function(method,args,hasBody){
29                        var send = windowName.send;
30                        var load = args.load;
31                        args.load = undefined; //we don't want send to set this callback
32                        var dfd = (httpAdapter ? httpAdapter(send, true) : send)(method, args, hasBody); // use the windowName transport
33                        dfd.addCallback(function(result){
34                                var ioArgs = dfd.ioArgs;
35                                ioArgs.xhr = {
36                                        getResponseHeader: function(name){
37                                                // convert the hash to an object to act like response headers
38                                                return dojo.queryToObject(ioArgs.hash.match(/[^#]*$/)[0])[name];
39                                        }
40                                };
41                                // use the XHR content handlers for handling
42                                if(ioArgs.handleAs == 'json'){
43                                        // use a secure json verifier, using object capability validator for now
44                                        if(!trusted){
45                                                capability.validate(result,["Date"],{});
46                                        }
47                                        return dojo.fromJson(result);
48                                }
49                                return dojo._contentHandlers[ioArgs.handleAs || "text"]({responseText:result});
50                        });
51                        args.load = load;
52                        if(load){
53                                dfd.addCallback(load);
54                        }
55                        return dfd;
56                }
57        );
58};
59
60return dojox.io.xhrWindowNamePlugin;
61});
Note: See TracBrowser for help on using the repository browser.