~ubuntu-branches/ubuntu/lucid/loggerhead/lucid-security

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/yui/build/io/io-base-debug.js

  • Committer: Bazaar Package Importer
  • Author(s): James Westby, Roland Mas, Jelmer Vernooij, James Westby
  • Date: 2009-08-26 13:18:03 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090826131803-0ce1fhaetci8b0c5
Tags: 1.17-0ubuntu1
[ Roland Mas ]
* Use the YUI library provided by libjs-yui. (Closes: #511286)

[ Jelmer Vernooij ]
* Use my debian.org address in Uploaders field.
* Add ${misc:Depends} to please lintian.
* Suggest recent version of paste, which doesn't expose internal port
  numbers in links. (Closes: #507000)
* Bump standards version to 3.8.1.

[ James Westby ]
* New upstream release.
* Drop get-orig-source rule in favour of debian/watch.
* Add python-pkg-resources and python-paste to Build-Depends,
  python-pkg-resources to Depends and python-simplejson to
  Recommends due to dependency changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
 
3
Code licensed under the BSD License:
 
4
http://developer.yahoo.net/yui/license.txt
 
5
version: 3.0.0pr2
 
6
*/
 
7
YUI.add('io-base', function(Y) {
 
8
 
 
9
   /**
 
10
        * HTTP communications module.
 
11
        * @module io
 
12
        */
 
13
 
 
14
   /**
 
15
    * The io class is a utility that brokers HTTP requests through a simplified
 
16
    * interface.  Specifically, it allows JavaScript to make HTTP requests to
 
17
    * a resource without a page reload.  The underlying transport for making
 
18
    * same-domain requests is the XMLHttpRequest object.  YUI.io can also use
 
19
    * Flash, if specified as a transport, for cross-domain requests.
 
20
    *
 
21
        * @class io
 
22
        */
 
23
 
 
24
   /**
 
25
        * @event io:start
 
26
        * @description This event is fired by YUI.io when a transaction is initiated..
 
27
        * @type Event Custom
 
28
        */
 
29
        var E_START = 'io:start',
 
30
 
 
31
   /**
 
32
        * @event io:complete
 
33
        * @description This event is fired by YUI.io when a transaction is complete and
 
34
        * all response data are available.
 
35
        * @type Event Custom
 
36
        */
 
37
        E_COMPLETE = 'io:complete',
 
38
 
 
39
   /**
 
40
        * @event io:success
 
41
        * @description This event is fired by YUI.io when a transaction is complete and
 
42
        * the HTTP status resolves to HTTP2xx.
 
43
        * @type Event Custom
 
44
        */
 
45
        E_SUCCESS = 'io:success',
 
46
 
 
47
   /**
 
48
        * @event io:failure
 
49
        * @description This event is fired by YUI.io when a transaction is complete and
 
50
        * the HTTP status resolves to HTTP4xx, 5xx and above.
 
51
        * @type Event Custom
 
52
        */
 
53
        E_FAILURE = 'io:failure',
 
54
 
 
55
   /**
 
56
        * @event io:abort
 
57
        * @description This event is fired by YUI.io when a transaction is aborted
 
58
        * explicitly or by a defined config.timeout.
 
59
        * @type Event Custom
 
60
        */
 
61
        E_ABORT = 'io:abort',
 
62
 
 
63
        //--------------------------------------
 
64
        //  Properties
 
65
        //--------------------------------------
 
66
   /**
 
67
        * @description A transaction counter that increments for each transaction.
 
68
        *
 
69
        * @property transactionId
 
70
        * @private
 
71
        * @static
 
72
        * @type int
 
73
        */
 
74
        transactionId = 0,
 
75
 
 
76
   /**
 
77
        * @description Object of default HTTP headers to be initialized and sent
 
78
        * for all transactions.
 
79
        *
 
80
        * @property _headers
 
81
        * @private
 
82
        * @static
 
83
        * @type object
 
84
        */
 
85
        _headers = {
 
86
                'X-Requested-With' : 'XMLHttpRequest'
 
87
        },
 
88
 
 
89
   /**
 
90
        * @description Object that stores timeout values for any transaction with
 
91
        * a defined "timeout" configuration property.
 
92
        *
 
93
        * @property _timeOut
 
94
        * @private
 
95
        * @static
 
96
        * @type object
 
97
        */
 
98
        _timeout = {};
 
99
 
 
100
        //--------------------------------------
 
101
        //  Methods
 
102
        //--------------------------------------
 
103
 
 
104
        // Window reference
 
105
        w = Y.config.win;
 
106
 
 
107
   /**
 
108
        * @description Method for requesting a transaction. _io() is implemented as
 
109
        * yui.io().  Each transaction may include a configuration object.  Its
 
110
        * properties are:
 
111
        *
 
112
        * method: HTTP method verb (e.g., GET or POST). If this property is not
 
113
        *         not defined, the default value will be GET.
 
114
        *
 
115
        * data: This is the name-value string that will be sent as the transaction
 
116
    *           data.  If the request is HTTP GET, the data become part of
 
117
    *           querystring. If HTTP POST, the data are sent in the message body.
 
118
        *
 
119
        * xdr: Defines the transport to be used for cross-domain requests.  By
 
120
        *      setting this property, the transaction will use the specified
 
121
        *      transport instead of XMLHttpRequest.  Currently, the only alternate
 
122
        *      transport supported is Flash (e.g., { xdr: 'flash' }).
 
123
        *
 
124
        * form: This is a defined object used to process HTML form as data.  The
 
125
        *       properties are:
 
126
        *       {
 
127
        *             id: object, //HTML form object or id of HTML form
 
128
        *         useDisabled: boolean, //Allow disabled HTML form field values
 
129
        *                      to be sent as part of the data.
 
130
    *       }
 
131
    *
 
132
    * on: This is a defined object used to create and handle specific
 
133
    *     events during a transaction lifecycle.  These events will fire in
 
134
    *     addition to the global io events. The events are:
 
135
    *     start - This event is fired when a request is sent to a resource.
 
136
    *     complete - This event fires when the transaction is complete.
 
137
    *     success - This event fires when the response status resolves to
 
138
    *               HTTP 2xx.
 
139
    *     failure - This event fires when the response status resolves to
 
140
    *               HTTP 4xx, 5xx, and beyond.
 
141
    *     abort - This even is fired when a transaction abort is fire by
 
142
    *             timeout, or when it is manually aborted.
 
143
    *
 
144
    *     The properties are:
 
145
    *     {
 
146
        *       start: function(id, args){},
 
147
        *       complete: function(id, responseobject, args){},
 
148
        *       success: function(id, responseobject, args){},
 
149
        *       failure: function(id, responseobject, args){},
 
150
        *       abort: function(id, args){}
 
151
        *     }
 
152
        *         Each property can reference a function or be written as an
 
153
        *     inline function.
 
154
        *
 
155
        * context: Object reference for an event handler when it is implemented
 
156
        *          as a method of a base object. Defining "context" will preserve
 
157
        *          the proper reference of "this" used in the event handler.
 
158
        * headers: This is a defined object of client headers, as many as.
 
159
        *         desired for the transaction.  These headers are sentThe object
 
160
        *         pattern is:
 
161
        *                 {
 
162
        *                   header: value
 
163
        *         }
 
164
        *
 
165
        * timeout: This value, defined as milliseconds, is a time threshold for the
 
166
        *          transaction. When this threshold is reached, and the transaction's
 
167
        *          Complete event has not yet fired, the transaction will be aborted.
 
168
        * arguments: Object, array, string, or number passed to all registered
 
169
        *            event handlers.  This value is available as the second
 
170
        *            argument in the "start" and "abort" event handlers; and, it is
 
171
        *            the third argument in the "complete", "success", and "failure"
 
172
        *            event handlers.
 
173
        *
 
174
        * @method _io
 
175
        * @private
 
176
        * @static
 
177
    * @param {string} uri - qualified path to transaction resource.
 
178
    * @param {object} c - configuration object for the transaction.
 
179
    * @return object
 
180
        */
 
181
        function _io(uri, c) {
 
182
                var c = c || {},
 
183
                o = _create((arguments.length === 3) ? arguments[2] : null, c),
 
184
                m = (c.method) ? c.method.toUpperCase() : 'GET',
 
185
                d = (c.data) ? c.data : null,
 
186
                f;
 
187
 
 
188
                /* Determine configuration properties */
 
189
                // If config.form is defined, perform data operations.
 
190
                if (c.form) {
 
191
 
 
192
                        if (c.form.upload) {
 
193
                                u = Y.io._upload(o, uri, c);
 
194
                                return u;
 
195
                        }
 
196
 
 
197
                        // Serialize the HTML form into a string of name-value pairs.
 
198
                        f = Y.io._serialize(c.form);
 
199
                        // If config.data is defined, concatenate the data to the form string.
 
200
                        if (d) {
 
201
                                f += "&" + d;
 
202
                                Y.log('Configuration object.data added to serialized HTML form data. The string is: ' + f, 'info', 'io');
 
203
                        }
 
204
 
 
205
                        if (m === 'POST') {
 
206
                                d = f;
 
207
                                _setHeader('Content-Type', 'application/x-www-form-urlencoded');
 
208
                        }
 
209
                        else if (m === 'GET') {
 
210
                                uri = _concat(uri, f);
 
211
                                Y.log('Configuration object.data added to serialized HTML form data. The querystring is: ' + uri, 'info', 'io');
 
212
                        }
 
213
                }
 
214
                else if (d && m === 'GET') {
 
215
                        uri = _concat(uri, c.data);
 
216
                        Y.log('Configuration object data added to URI. The querystring is: ' + uri, 'info', 'io');
 
217
                }
 
218
                else if (d && m === 'POST') {
 
219
                        _setHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
 
220
                }
 
221
 
 
222
                if (c.xdr) {
 
223
                        Y.io._xdr(uri, o, c);
 
224
                        return o;
 
225
                }
 
226
 
 
227
                // If config.timeout is defined, and the request is standard XHR,
 
228
                // initialize timeout polling.
 
229
                if (c.timeout) {
 
230
                        _startTimeout(o, c);
 
231
                }
 
232
                /* End Configuration Properties */
 
233
 
 
234
                o.c.onreadystatechange = function() { _readyState(o, c); };
 
235
                try {
 
236
                        _open(o.c, m, uri);
 
237
                }
 
238
                catch (e) {
 
239
                }
 
240
                _setHeaders(o.c, (c.headers || {}));
 
241
 
 
242
                o.abort = function () {
 
243
                        _ioAbort(o, c);
 
244
                }
 
245
 
 
246
                o.isInProgress = function() {
 
247
                        return o.c.readyState !== 4 && o.c.readyState !== 0;
 
248
                }
 
249
                // Do not pass null, in the absence of data, as this
 
250
                // will result in a POST request with no Content-Length
 
251
                // defined.
 
252
                _async(o, (d || ''), c);
 
253
 
 
254
                return o;
 
255
        };
 
256
 
 
257
   /**
 
258
        * @description Method for creating and subscribing transaction events.
 
259
        *
 
260
        * @method _tPubSub
 
261
        * @private
 
262
        * @static
 
263
        * @param {string} e - event to be published
 
264
        * @param {object} c - configuration object for the transaction.
 
265
        *
 
266
    * @return void
 
267
        */
 
268
        function _tPubSub(e, c){
 
269
                        var event = new Y.Event.Target().publish('transaction:' + e);
 
270
                        event.subscribe(c.on[e], (c.context || this), c.arguments);
 
271
 
 
272
                        return event;
 
273
        };
 
274
 
 
275
   /**
 
276
        * @description Fires event "io:start" and creates, fires a
 
277
        * transaction-specific start event, if config.on.start is
 
278
        * defined.
 
279
        *
 
280
        * @method _ioStart
 
281
        * @private
 
282
        * @static
 
283
        * @param {number} id - transaction id
 
284
        * @param {object} c - configuration object for the transaction.
 
285
        *
 
286
    * @return void
 
287
        */
 
288
        function _ioStart(id, c) {
 
289
                // Set default value of argument c, property "on" to Object if
 
290
                // the property is null or undefined.
 
291
                c.on = c.on || {};
 
292
                var m = Y.io._fn || {},
 
293
                fn = (m && m[id]) ? m[id] : null,
 
294
                event;
 
295
 
 
296
                if (fn) {
 
297
                        c.on.start = fn.start;
 
298
                        delete fn;
 
299
                }
 
300
 
 
301
                Y.fire(E_START, id);
 
302
                if (c.on.start) {
 
303
                        event = _tPubSub('start', c);
 
304
                        event.fire(id);
 
305
                }
 
306
                Y.log('Transaction ' + id + ' started.', 'info', 'io');
 
307
        };
 
308
 
 
309
   /**
 
310
        * @description Fires event "io:complete" and creates, fires a
 
311
        * transaction-specific "complete" event, if config.on.complete is
 
312
        * defined.
 
313
        *
 
314
        * @method _ioComplete
 
315
        * @private
 
316
        * @static
 
317
        * @param {object} o - transaction object.
 
318
        * @param {object} c - configuration object for the transaction.
 
319
        *
 
320
    * @return void
 
321
        */
 
322
        function _ioComplete(o, c) {
 
323
                // Set default value of argument c, property "on" to Object if
 
324
                // the property is null or undefined.
 
325
                c.on = c.on || {};
 
326
                var event;
 
327
 
 
328
                Y.fire(E_COMPLETE, o.id, o.c);
 
329
                if (c.on.complete) {
 
330
                        event = _tPubSub('complete', c);
 
331
                        event.fire(o.id, o.c);
 
332
                }
 
333
                Y.log('Transaction ' + o.id + ' completed.', 'info', 'io');
 
334
        }
 
335
 
 
336
   /**
 
337
        * @description Fires event "io:success" and creates, fires a
 
338
        * transaction-specific "success" event, if config.on.success is
 
339
        * defined.
 
340
        *
 
341
        * @method _ioSuccess
 
342
        * @private
 
343
        * @static
 
344
        * @param {object} o - transaction object.
 
345
        * @param {object} c - configuration object for the transaction.
 
346
        *
 
347
    * @return void
 
348
        */
 
349
        function _ioSuccess(o, c) {
 
350
                // Set default value of argument c, property "on" to Object if
 
351
                // the property is null or undefined.
 
352
                c.on = c.on || {};
 
353
                var m = Y.io._fn || {},
 
354
                fn = (m && m[o.id]) ? m[o.id] : null,
 
355
                event;
 
356
 
 
357
                if (fn) {
 
358
                        c.on.success = fn.success;
 
359
                        delete fn;
 
360
                        //Decode the response from IO.swf
 
361
                        o.c.responseText = decodeURI(o.c.responseText);
 
362
                }
 
363
 
 
364
                Y.fire(E_SUCCESS, o.id, o.c);
 
365
                if (c.on.success) {
 
366
                        event = _tPubSub('success', c);
 
367
                        event.fire(o.id, o.c);
 
368
                }
 
369
 
 
370
                _destroy(o, (c.xdr) ? true : false );
 
371
                Y.log('HTTP Status evaluates to Success. The transaction is: ' + o.id, 'info', 'io');
 
372
        }
 
373
 
 
374
   /**
 
375
        * @description Fires event "io:failure" and creates, fires a
 
376
        * transaction-specific "failure" event, if config.on.failure is
 
377
        * defined.
 
378
        *
 
379
        * @method _ioFailure
 
380
        * @private
 
381
        * @static
 
382
        * @param {object} o - transaction object.
 
383
        * @param {object} c - configuration object for the transaction.
 
384
        *
 
385
    * @return void
 
386
        */
 
387
        function _ioFailure(o, c) {
 
388
                // Set default value of argument c, property "on" to Object if
 
389
                // the property is null or undefined.
 
390
                c.on = c.on || {};
 
391
                var m = Y.io._fn || {},
 
392
                fn = (m && m[o.id]) ? m[o.id] : null,
 
393
                event;
 
394
 
 
395
                if (fn) {
 
396
                        c.on.failure = fn.failure;
 
397
                        delete fn;
 
398
                        //Decode the response from IO.swf
 
399
                        o.c.responseText = decodeURI(o.c.responseText);
 
400
                }
 
401
 
 
402
                Y.fire(E_FAILURE, o.id, o.c);
 
403
                if (c.on.failure) {
 
404
                        event = _tPubSub('failure', c);
 
405
                        event.fire(o.id, o.c);
 
406
                }
 
407
 
 
408
                _destroy(o, (c.xdr) ? true : false );
 
409
                Y.log('HTTP Status evaluates to Failure. The transaction is: ' + o.id, 'info', 'io');
 
410
        }
 
411
 
 
412
   /**
 
413
        * @description Fires event "io:abort" and creates, fires a
 
414
        * transaction-specific "abort" event, if config.on.abort is
 
415
        * defined.
 
416
        *
 
417
        * @method _ioAbort
 
418
        * @private
 
419
        * @static
 
420
    * @param {object} o - Transaction object generated by _create().
 
421
    * @param {object} c - Configuration object passed to YUI.io().
 
422
        *
 
423
    * @return void
 
424
        */
 
425
        function _ioAbort(o, c) {
 
426
                // Set default value of argument c, property "on" to Object if
 
427
                // the property is null or undefined.
 
428
                c.on = c.on || {};
 
429
                var m = Y.io._fn || {},
 
430
                fn = (m && m[o.id]) ? m[o.id] : null,
 
431
                event;
 
432
 
 
433
                if(o && o.c  && !c.xdr) {
 
434
                        // Terminate the transaction
 
435
                        o.c.abort();
 
436
                        if (c) {
 
437
                                // Clear the timeout poll for this specific transaction.
 
438
                                if (c.timeout) {
 
439
                                        _clearTimeout(o.id);
 
440
                                }
 
441
                        }
 
442
                }
 
443
 
 
444
                if (fn) {
 
445
                        c.on.abort = fn.abort;
 
446
                        delete fn;
 
447
                }
 
448
 
 
449
                Y.fire(E_ABORT, o.id);
 
450
                if (c.on.abort) {
 
451
                        event = _tPubSub('abort', c);
 
452
                        event.fire(id);
 
453
                }
 
454
 
 
455
                _destroy(o, (c.xdr) ? true : false );
 
456
                Y.log('Transaction timeout or explicit abort. The transaction is: ' + o.id, 'info', 'io');
 
457
        }
 
458
 
 
459
   /**
 
460
        * @description Method that increments _transactionId for each transaction.
 
461
        *
 
462
        * @method _id
 
463
        * @private
 
464
        * @static
 
465
    * @return int
 
466
        */
 
467
        function _id() {
 
468
                var id = transactionId;
 
469
                transactionId++;
 
470
 
 
471
                Y.log('Transaction id generated. The id is: ' + id, 'info', 'io');
 
472
                return id;
 
473
        };
 
474
 
 
475
   /**
 
476
        * @description Method that creates a unique transaction object for each
 
477
        * request..
 
478
        *
 
479
        * @method _create
 
480
        * @private
 
481
        * @static
 
482
    * @param {number} s - URI or root data.
 
483
    * @param {number} c - configuration object
 
484
    * @return object
 
485
        */
 
486
        function _create(i, c) {
 
487
                var o = {};
 
488
                o.id = Y.Lang.isNumber(i) ? i : _id();
 
489
 
 
490
                if (c.xdr) {
 
491
                        o.c = Y.io._transportMap[c.xdr.use];
 
492
                }
 
493
                else if (c.form && c.form.upload) {
 
494
                        o.c = {};
 
495
                }
 
496
                else {
 
497
                        o.c = _xhr();
 
498
                }
 
499
 
 
500
                return o;
 
501
        };
 
502
 
 
503
   /**
 
504
        * @description Method that creates the XMLHttpRequest transport
 
505
        *
 
506
        * @method _xhr
 
507
        * @private
 
508
        * @static
 
509
    * @return object
 
510
        */
 
511
        function _xhr() {
 
512
                return (w.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
 
513
        };
 
514
 
 
515
   /**
 
516
        * @description Method that concatenates string data for HTTP GET transactions.
 
517
        *
 
518
        * @method _concat
 
519
        * @private
 
520
        * @static
 
521
    * @param {string} s - URI or root data.
 
522
    * @param {string} d - data to be concatenated onto URI.
 
523
    * @return int
 
524
        */
 
525
        function _concat(s, d) {
 
526
                s += ((s.indexOf('?') == -1) ? '?' : '&') + d;
 
527
                return s;
 
528
        };
 
529
 
 
530
   /**
 
531
        * @description Method that stores default client headers for all transactions.
 
532
        * If a label is passed with no value argument, the header will be deleted.
 
533
        *
 
534
        * @method _setHeader
 
535
        * @private
 
536
        * @static
 
537
    * @param {string} l - HTTP header
 
538
    * @param {string} v - HTTP header value
 
539
    * @return int
 
540
        */
 
541
        function _setHeader(l, v) {
 
542
                if (v) {
 
543
                        _headers[l] = v;
 
544
                }
 
545
                else {
 
546
                        delete _headers[l];
 
547
                }
 
548
        };
 
549
 
 
550
   /**
 
551
        * @description Method that sets all HTTP headers to be sent in a transaction.
 
552
        *
 
553
        * @method _setHeaders
 
554
        * @private
 
555
        * @static
 
556
    * @param {object} o - XHR instance for the specific transaction.
 
557
    * @param {object} h - HTTP headers for the specific transaction, as defined
 
558
    *                     in the configuration object passed to YUI.io().
 
559
    * @return void
 
560
        */
 
561
        function _setHeaders(o, h) {
 
562
 
 
563
                var p;
 
564
 
 
565
                for (p in _headers) {
 
566
                        if (_headers.hasOwnProperty(p)) {
 
567
                                if (h[p]) {
 
568
                                        // Configuration headers will supersede IO preset headers,
 
569
                                        // if headers match.
 
570
                                        Y.log('Matching configuration HTTP header: ' + p + ' found with value of ' + _headers[p], 'info', 'io');
 
571
                                        break;
 
572
                                }
 
573
                                else {
 
574
                                        h[p] = _headers[p];
 
575
                                        Y.log('HTTP header ' + p + ' found with value of ' + _headers[p], 'info', 'io');
 
576
                                }
 
577
                        }
 
578
                }
 
579
 
 
580
                for (p in h) {
 
581
                        if (h.hasOwnProperty(p)) {
 
582
                                o.setRequestHeader(p, h[p]);
 
583
                                Y.log('HTTP Header ' + p + ' set with value of ' + h[p], 'info', 'io');
 
584
                        }
 
585
                }
 
586
        };
 
587
 
 
588
        function _open(o, m, uri) {
 
589
                o.open(m, uri, true);
 
590
        };
 
591
 
 
592
   /**
 
593
        * @description Method that sends the transaction request.
 
594
        *
 
595
        * @method _async
 
596
        * @private
 
597
        * @static
 
598
    * @param {object} o - Transaction object generated by _create().
 
599
    * @param {string} d - Transaction data.
 
600
    * @param {object} c - Configuration object passed to YUI.io().
 
601
    * @return void
 
602
        */
 
603
        function _async(o, d, c) {
 
604
                o.c.send(d);
 
605
                _ioStart(o.id, c);
 
606
        };
 
607
 
 
608
   /**
 
609
        * @description Starts timeout count if the configuration object
 
610
        * has a defined timeout property.
 
611
        *
 
612
        * @method _startTimeout
 
613
        * @private
 
614
        * @static
 
615
    * @param {object} o - Transaction object generated by _create().
 
616
    * @param {object} c - Configuration object passed to YUI.io().
 
617
    * @return void
 
618
        */
 
619
        function _startTimeout(o, c) {
 
620
                _timeout[o.id] = w.setTimeout(function() { _ioAbort(o, c); }, c.timeout);
 
621
        };
 
622
 
 
623
   /**
 
624
        * @description Clears the timeout interval started by _startTimeout().
 
625
        *
 
626
        * @method _clearTimeout
 
627
        * @private
 
628
        * @static
 
629
    * @param {number} id - Transaction id.
 
630
    * @return void
 
631
        */
 
632
        function _clearTimeout(id) {
 
633
                w.clearTimeout(_timeout[id]);
 
634
                delete _timeout[id];
 
635
        };
 
636
 
 
637
   /**
 
638
        * @description Event handler bound to onreadystatechange.
 
639
        *
 
640
        * @method _readyState
 
641
        * @private
 
642
        * @static
 
643
    * @param {object} o - Transaction object generated by _create().
 
644
    * @param {object} c - Configuration object passed to YUI.io().
 
645
    * @return void
 
646
        */
 
647
        function _readyState(o, c) {
 
648
                if (o.c.readyState === 4) {
 
649
                        if (c.timeout) {
 
650
                                _clearTimeout(o.id);
 
651
                        }
 
652
                        _ioComplete(o, c);
 
653
                        _handleResponse(o, c);
 
654
                }
 
655
        };
 
656
 
 
657
   /**
 
658
        * @description Method that determines if a transaction response qualifies
 
659
        * as success or failure, based on the response HTTP status code, and
 
660
        * fires the appropriate success or failure events.
 
661
        *
 
662
        * @method _handleResponse
 
663
        * @private
 
664
        * @static
 
665
    * @param {object} o - Transaction object generated by _create().
 
666
    * @param {object} c - Configuration object passed to YUI.io().
 
667
    * @return void
 
668
        */
 
669
        function _handleResponse(o, c) {
 
670
                var status;
 
671
                try{
 
672
                        if (o.c.status && o.c.status !== 0) {
 
673
                                status = o.c.status;
 
674
                        }
 
675
                        else {
 
676
                                status = 0;
 
677
                        }
 
678
                }
 
679
                catch(e) {
 
680
                        status = 0;
 
681
                        Y.log('HTTP status unreadable. The transaction is: ' + o.id, 'warn', 'io');
 
682
                }
 
683
 
 
684
                /*
 
685
                 * IE reports HTTP 204 as HTTP 1223.
 
686
                 * However, the response data are still available.
 
687
                 *
 
688
                 * setTimeout() is used to prevent transactions from becoming
 
689
                 * synchronous, in IE, when the response data are read from cache
 
690
                 * (e.g., HTTP 304).
 
691
                 */
 
692
                if (status >= 200 && status < 300 || status === 1223) {
 
693
                        w.setTimeout( function() { _ioSuccess(o, c); }, 0);
 
694
                }
 
695
                else {
 
696
                        w.setTimeout( function() {_ioFailure(o, c); }, 0);
 
697
                }
 
698
        };
 
699
 
 
700
        function _destroy(o, isTransport) {
 
701
                // IE6 will throw a "Type Mismatch" error if the event handler is set to "null".
 
702
                if(w.XMLHttpRequest && !isTransport) {
 
703
                        if (o.c) {
 
704
                                o.c.onreadystatechange = null;
 
705
                        }
 
706
                }
 
707
 
 
708
                o.c = null;
 
709
                o = null;
 
710
        };
 
711
 
 
712
        _io.start = _ioStart;
 
713
        _io.complete = _ioComplete;
 
714
        _io.success = _ioSuccess;
 
715
        _io.failure = _ioFailure;
 
716
        _io.abort = _ioAbort;
 
717
        _io._id = _id;
 
718
        _io._timeout = _timeout;
 
719
 
 
720
        //--------------------------------------
 
721
        //  Begin public interface definition
 
722
        //--------------------------------------
 
723
   /**
 
724
        * @description Method that stores default client headers for all transactions.
 
725
        * If a label is passed with no value argument, the header will be deleted.
 
726
        * This is the interface for _setHeader().
 
727
        *
 
728
        * @method header
 
729
        * @public
 
730
        * @static
 
731
    * @param {string} l - HTTP header
 
732
    * @param {string} v - HTTP header value
 
733
    * @return int
 
734
        */
 
735
        _io.header = _setHeader;
 
736
 
 
737
   /**
 
738
        * @description Method for requesting a transaction. This
 
739
        * is the interface for _io().
 
740
        *
 
741
        * @method io
 
742
        * @public
 
743
        * @static
 
744
    * @param {string} uri - qualified path to transaction resource.
 
745
    * @param {object} c - configuration object for the transaction.
 
746
    * @return object
 
747
    */
 
748
        Y.io = _io;
 
749
 
 
750
 
 
751
 
 
752
}, '3.0.0pr2' );