-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.js
1106 lines (1091 loc) · 47.9 KB
/
http.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"format register";
System.register("angular2/src/http/interfaces", [], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var ConnectionBackend = (function() {
function ConnectionBackend() {}
return ConnectionBackend;
}());
exports.ConnectionBackend = ConnectionBackend;
var Connection = (function() {
function Connection() {}
return Connection;
}());
exports.Connection = Connection;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/headers", ["angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/src/facade/collection"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var lang_1 = require("angular2/src/facade/lang");
var exceptions_1 = require("angular2/src/facade/exceptions");
var collection_1 = require("angular2/src/facade/collection");
var Headers = (function() {
function Headers(headers) {
var _this = this;
if (headers instanceof Headers) {
this._headersMap = headers._headersMap;
return ;
}
this._headersMap = new collection_1.Map();
if (lang_1.isBlank(headers)) {
return ;
}
collection_1.StringMapWrapper.forEach(headers, function(v, k) {
_this._headersMap.set(k, collection_1.isListLikeIterable(v) ? v : [v]);
});
}
Headers.fromResponseHeaderString = function(headersString) {
return headersString.trim().split('\n').map(function(val) {
return val.split(':');
}).map(function(_a) {
var key = _a[0],
parts = _a.slice(1);
return ([key.trim(), parts.join(':').trim()]);
}).reduce(function(headers, _a) {
var key = _a[0],
value = _a[1];
return !headers.set(key, value) && headers;
}, new Headers());
};
Headers.prototype.append = function(name, value) {
var mapName = this._headersMap.get(name);
var list = collection_1.isListLikeIterable(mapName) ? mapName : [];
list.push(value);
this._headersMap.set(name, list);
};
Headers.prototype.delete = function(name) {
this._headersMap.delete(name);
};
Headers.prototype.forEach = function(fn) {
this._headersMap.forEach(fn);
};
Headers.prototype.get = function(header) {
return collection_1.ListWrapper.first(this._headersMap.get(header));
};
Headers.prototype.has = function(header) {
return this._headersMap.has(header);
};
Headers.prototype.keys = function() {
return collection_1.MapWrapper.keys(this._headersMap);
};
Headers.prototype.set = function(header, value) {
var list = [];
if (collection_1.isListLikeIterable(value)) {
var pushValue = value.join(',');
list.push(pushValue);
} else {
list.push(value);
}
this._headersMap.set(header, list);
};
Headers.prototype.values = function() {
return collection_1.MapWrapper.values(this._headersMap);
};
Headers.prototype.toJSON = function() {
var serializableHeaders = {};
this._headersMap.forEach(function(values, name) {
var list = [];
collection_1.iterateListLike(values, function(val) {
return list = collection_1.ListWrapper.concat(list, val.split(','));
});
serializableHeaders[name] = list;
});
return serializableHeaders;
};
Headers.prototype.getAll = function(header) {
var headers = this._headersMap.get(header);
return collection_1.isListLikeIterable(headers) ? headers : [];
};
Headers.prototype.entries = function() {
throw new exceptions_1.BaseException('"entries" method is not implemented on Headers class');
};
return Headers;
}());
exports.Headers = Headers;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/enums", [], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
(function(RequestMethod) {
RequestMethod[RequestMethod["Get"] = 0] = "Get";
RequestMethod[RequestMethod["Post"] = 1] = "Post";
RequestMethod[RequestMethod["Put"] = 2] = "Put";
RequestMethod[RequestMethod["Delete"] = 3] = "Delete";
RequestMethod[RequestMethod["Options"] = 4] = "Options";
RequestMethod[RequestMethod["Head"] = 5] = "Head";
RequestMethod[RequestMethod["Patch"] = 6] = "Patch";
})(exports.RequestMethod || (exports.RequestMethod = {}));
var RequestMethod = exports.RequestMethod;
(function(ReadyState) {
ReadyState[ReadyState["Unsent"] = 0] = "Unsent";
ReadyState[ReadyState["Open"] = 1] = "Open";
ReadyState[ReadyState["HeadersReceived"] = 2] = "HeadersReceived";
ReadyState[ReadyState["Loading"] = 3] = "Loading";
ReadyState[ReadyState["Done"] = 4] = "Done";
ReadyState[ReadyState["Cancelled"] = 5] = "Cancelled";
})(exports.ReadyState || (exports.ReadyState = {}));
var ReadyState = exports.ReadyState;
(function(ResponseType) {
ResponseType[ResponseType["Basic"] = 0] = "Basic";
ResponseType[ResponseType["Cors"] = 1] = "Cors";
ResponseType[ResponseType["Default"] = 2] = "Default";
ResponseType[ResponseType["Error"] = 3] = "Error";
ResponseType[ResponseType["Opaque"] = 4] = "Opaque";
})(exports.ResponseType || (exports.ResponseType = {}));
var ResponseType = exports.ResponseType;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/url_search_params", ["angular2/src/facade/lang", "angular2/src/facade/collection"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var lang_1 = require("angular2/src/facade/lang");
var collection_1 = require("angular2/src/facade/collection");
function paramParser(rawParams) {
if (rawParams === void 0) {
rawParams = '';
}
var map = new collection_1.Map();
if (rawParams.length > 0) {
var params = rawParams.split('&');
params.forEach(function(param) {
var split = param.split('=');
var key = split[0];
var val = split[1];
var list = lang_1.isPresent(map.get(key)) ? map.get(key) : [];
list.push(val);
map.set(key, list);
});
}
return map;
}
var URLSearchParams = (function() {
function URLSearchParams(rawParams) {
if (rawParams === void 0) {
rawParams = '';
}
this.rawParams = rawParams;
this.paramsMap = paramParser(rawParams);
}
URLSearchParams.prototype.clone = function() {
var clone = new URLSearchParams();
clone.appendAll(this);
return clone;
};
URLSearchParams.prototype.has = function(param) {
return this.paramsMap.has(param);
};
URLSearchParams.prototype.get = function(param) {
var storedParam = this.paramsMap.get(param);
if (collection_1.isListLikeIterable(storedParam)) {
return collection_1.ListWrapper.first(storedParam);
} else {
return null;
}
};
URLSearchParams.prototype.getAll = function(param) {
var mapParam = this.paramsMap.get(param);
return lang_1.isPresent(mapParam) ? mapParam : [];
};
URLSearchParams.prototype.set = function(param, val) {
var mapParam = this.paramsMap.get(param);
var list = lang_1.isPresent(mapParam) ? mapParam : [];
collection_1.ListWrapper.clear(list);
list.push(val);
this.paramsMap.set(param, list);
};
URLSearchParams.prototype.setAll = function(searchParams) {
var _this = this;
searchParams.paramsMap.forEach(function(value, param) {
var mapParam = _this.paramsMap.get(param);
var list = lang_1.isPresent(mapParam) ? mapParam : [];
collection_1.ListWrapper.clear(list);
list.push(value[0]);
_this.paramsMap.set(param, list);
});
};
URLSearchParams.prototype.append = function(param, val) {
var mapParam = this.paramsMap.get(param);
var list = lang_1.isPresent(mapParam) ? mapParam : [];
list.push(val);
this.paramsMap.set(param, list);
};
URLSearchParams.prototype.appendAll = function(searchParams) {
var _this = this;
searchParams.paramsMap.forEach(function(value, param) {
var mapParam = _this.paramsMap.get(param);
var list = lang_1.isPresent(mapParam) ? mapParam : [];
for (var i = 0; i < value.length; ++i) {
list.push(value[i]);
}
_this.paramsMap.set(param, list);
});
};
URLSearchParams.prototype.replaceAll = function(searchParams) {
var _this = this;
searchParams.paramsMap.forEach(function(value, param) {
var mapParam = _this.paramsMap.get(param);
var list = lang_1.isPresent(mapParam) ? mapParam : [];
collection_1.ListWrapper.clear(list);
for (var i = 0; i < value.length; ++i) {
list.push(value[i]);
}
_this.paramsMap.set(param, list);
});
};
URLSearchParams.prototype.toString = function() {
var paramsList = [];
this.paramsMap.forEach(function(values, k) {
values.forEach(function(v) {
return paramsList.push(k + '=' + v);
});
});
return paramsList.join('&');
};
URLSearchParams.prototype.delete = function(param) {
this.paramsMap.delete(param);
};
return URLSearchParams;
}());
exports.URLSearchParams = URLSearchParams;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/static_response", ["angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/src/http/http_utils"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var lang_1 = require("angular2/src/facade/lang");
var exceptions_1 = require("angular2/src/facade/exceptions");
var http_utils_1 = require("angular2/src/http/http_utils");
var Response = (function() {
function Response(responseOptions) {
this._body = responseOptions.body;
this.status = responseOptions.status;
this.statusText = responseOptions.statusText;
this.headers = responseOptions.headers;
this.type = responseOptions.type;
this.url = responseOptions.url;
}
Response.prototype.blob = function() {
throw new exceptions_1.BaseException('"blob()" method not implemented on Response superclass');
};
Response.prototype.json = function() {
var jsonResponse;
if (http_utils_1.isJsObject(this._body)) {
jsonResponse = this._body;
} else if (lang_1.isString(this._body)) {
jsonResponse = lang_1.Json.parse(this._body);
}
return jsonResponse;
};
Response.prototype.text = function() {
return this._body.toString();
};
Response.prototype.arrayBuffer = function() {
throw new exceptions_1.BaseException('"arrayBuffer()" method not implemented on Response superclass');
};
return Response;
}());
exports.Response = Response;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/base_response_options", ["angular2/core", "angular2/src/facade/lang", "angular2/src/http/headers", "angular2/src/http/enums"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var __extends = (this && this.__extends) || function(d, b) {
for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p];
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var core_1 = require("angular2/core");
var lang_1 = require("angular2/src/facade/lang");
var headers_1 = require("angular2/src/http/headers");
var enums_1 = require("angular2/src/http/enums");
var ResponseOptions = (function() {
function ResponseOptions(_a) {
var _b = _a === void 0 ? {} : _a,
body = _b.body,
status = _b.status,
headers = _b.headers,
statusText = _b.statusText,
type = _b.type,
url = _b.url;
this.body = lang_1.isPresent(body) ? body : null;
this.status = lang_1.isPresent(status) ? status : null;
this.headers = lang_1.isPresent(headers) ? headers : null;
this.statusText = lang_1.isPresent(statusText) ? statusText : null;
this.type = lang_1.isPresent(type) ? type : null;
this.url = lang_1.isPresent(url) ? url : null;
}
ResponseOptions.prototype.merge = function(options) {
return new ResponseOptions({
body: lang_1.isPresent(options) && lang_1.isPresent(options.body) ? options.body : this.body,
status: lang_1.isPresent(options) && lang_1.isPresent(options.status) ? options.status : this.status,
headers: lang_1.isPresent(options) && lang_1.isPresent(options.headers) ? options.headers : this.headers,
statusText: lang_1.isPresent(options) && lang_1.isPresent(options.statusText) ? options.statusText : this.statusText,
type: lang_1.isPresent(options) && lang_1.isPresent(options.type) ? options.type : this.type,
url: lang_1.isPresent(options) && lang_1.isPresent(options.url) ? options.url : this.url
});
};
return ResponseOptions;
}());
exports.ResponseOptions = ResponseOptions;
var BaseResponseOptions = (function(_super) {
__extends(BaseResponseOptions, _super);
function BaseResponseOptions() {
_super.call(this, {
status: 200,
statusText: 'Ok',
type: enums_1.ResponseType.Default,
headers: new headers_1.Headers()
});
}
BaseResponseOptions = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [])], BaseResponseOptions);
return BaseResponseOptions;
}(ResponseOptions));
exports.BaseResponseOptions = BaseResponseOptions;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/backends/browser_xhr", ["angular2/core"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var core_1 = require("angular2/core");
var BrowserXhr = (function() {
function BrowserXhr() {}
BrowserXhr.prototype.build = function() {
return (new XMLHttpRequest());
};
BrowserXhr = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [])], BrowserXhr);
return BrowserXhr;
}());
exports.BrowserXhr = BrowserXhr;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/backends/browser_jsonp", ["angular2/core", "angular2/src/facade/lang"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var core_1 = require("angular2/core");
var lang_1 = require("angular2/src/facade/lang");
var _nextRequestId = 0;
exports.JSONP_HOME = '__ng_jsonp__';
var _jsonpConnections = null;
function _getJsonpConnections() {
if (_jsonpConnections === null) {
_jsonpConnections = lang_1.global[exports.JSONP_HOME] = {};
}
return _jsonpConnections;
}
var BrowserJsonp = (function() {
function BrowserJsonp() {}
BrowserJsonp.prototype.build = function(url) {
var node = document.createElement('script');
node.src = url;
return node;
};
BrowserJsonp.prototype.nextRequestID = function() {
return "__req" + _nextRequestId++;
};
BrowserJsonp.prototype.requestCallback = function(id) {
return exports.JSONP_HOME + "." + id + ".finished";
};
BrowserJsonp.prototype.exposeConnection = function(id, connection) {
var connections = _getJsonpConnections();
connections[id] = connection;
};
BrowserJsonp.prototype.removeConnection = function(id) {
var connections = _getJsonpConnections();
connections[id] = null;
};
BrowserJsonp.prototype.send = function(node) {
document.body.appendChild((node));
};
BrowserJsonp.prototype.cleanup = function(node) {
if (node.parentNode) {
node.parentNode.removeChild((node));
}
};
BrowserJsonp = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [])], BrowserJsonp);
return BrowserJsonp;
}());
exports.BrowserJsonp = BrowserJsonp;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/http_utils", ["angular2/src/facade/lang", "angular2/src/http/enums", "angular2/src/facade/exceptions", "angular2/src/facade/lang"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var lang_1 = require("angular2/src/facade/lang");
var enums_1 = require("angular2/src/http/enums");
var exceptions_1 = require("angular2/src/facade/exceptions");
function normalizeMethodName(method) {
if (lang_1.isString(method)) {
var originalMethod = method;
method = method.replace(/(\w)(\w*)/g, function(g0, g1, g2) {
return g1.toUpperCase() + g2.toLowerCase();
});
method = enums_1.RequestMethod[method];
if (typeof method !== 'number')
throw exceptions_1.makeTypeError("Invalid request method. The method \"" + originalMethod + "\" is not supported.");
}
return method;
}
exports.normalizeMethodName = normalizeMethodName;
exports.isSuccess = function(status) {
return (status >= 200 && status < 300);
};
function getResponseURL(xhr) {
if ('responseURL' in xhr) {
return xhr.responseURL;
}
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
return xhr.getResponseHeader('X-Request-URL');
}
return ;
}
exports.getResponseURL = getResponseURL;
var lang_2 = require("angular2/src/facade/lang");
exports.isJsObject = lang_2.isJsObject;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/base_request_options", ["angular2/src/facade/lang", "angular2/src/http/headers", "angular2/src/http/enums", "angular2/core", "angular2/src/http/url_search_params", "angular2/src/http/http_utils"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var __extends = (this && this.__extends) || function(d, b) {
for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p];
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var lang_1 = require("angular2/src/facade/lang");
var headers_1 = require("angular2/src/http/headers");
var enums_1 = require("angular2/src/http/enums");
var core_1 = require("angular2/core");
var url_search_params_1 = require("angular2/src/http/url_search_params");
var http_utils_1 = require("angular2/src/http/http_utils");
var RequestOptions = (function() {
function RequestOptions(_a) {
var _b = _a === void 0 ? {} : _a,
method = _b.method,
headers = _b.headers,
body = _b.body,
url = _b.url,
search = _b.search;
this.method = lang_1.isPresent(method) ? http_utils_1.normalizeMethodName(method) : null;
this.headers = lang_1.isPresent(headers) ? headers : null;
this.body = lang_1.isPresent(body) ? body : null;
this.url = lang_1.isPresent(url) ? url : null;
this.search = lang_1.isPresent(search) ? (lang_1.isString(search) ? new url_search_params_1.URLSearchParams((search)) : (search)) : null;
}
RequestOptions.prototype.merge = function(options) {
return new RequestOptions({
method: lang_1.isPresent(options) && lang_1.isPresent(options.method) ? options.method : this.method,
headers: lang_1.isPresent(options) && lang_1.isPresent(options.headers) ? options.headers : this.headers,
body: lang_1.isPresent(options) && lang_1.isPresent(options.body) ? options.body : this.body,
url: lang_1.isPresent(options) && lang_1.isPresent(options.url) ? options.url : this.url,
search: lang_1.isPresent(options) && lang_1.isPresent(options.search) ? (lang_1.isString(options.search) ? new url_search_params_1.URLSearchParams((options.search)) : (options.search).clone()) : this.search
});
};
return RequestOptions;
}());
exports.RequestOptions = RequestOptions;
var BaseRequestOptions = (function(_super) {
__extends(BaseRequestOptions, _super);
function BaseRequestOptions() {
_super.call(this, {
method: enums_1.RequestMethod.Get,
headers: new headers_1.Headers()
});
}
BaseRequestOptions = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [])], BaseRequestOptions);
return BaseRequestOptions;
}(RequestOptions));
exports.BaseRequestOptions = BaseRequestOptions;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/backends/xhr_backend", ["angular2/src/http/enums", "angular2/src/http/static_response", "angular2/src/http/headers", "angular2/src/http/base_response_options", "angular2/core", "angular2/src/http/backends/browser_xhr", "angular2/src/facade/lang", "rxjs/Observable", "angular2/src/http/http_utils"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var enums_1 = require("angular2/src/http/enums");
var static_response_1 = require("angular2/src/http/static_response");
var headers_1 = require("angular2/src/http/headers");
var base_response_options_1 = require("angular2/src/http/base_response_options");
var core_1 = require("angular2/core");
var browser_xhr_1 = require("angular2/src/http/backends/browser_xhr");
var lang_1 = require("angular2/src/facade/lang");
var Observable_1 = require("rxjs/Observable");
var http_utils_1 = require("angular2/src/http/http_utils");
var XHRConnection = (function() {
function XHRConnection(req, browserXHR, baseResponseOptions) {
var _this = this;
this.request = req;
this.response = new Observable_1.Observable(function(responseObserver) {
var _xhr = browserXHR.build();
_xhr.open(enums_1.RequestMethod[req.method].toUpperCase(), req.url);
var onLoad = function() {
var body = lang_1.isPresent(_xhr.response) ? _xhr.response : _xhr.responseText;
var headers = headers_1.Headers.fromResponseHeaderString(_xhr.getAllResponseHeaders());
var url = http_utils_1.getResponseURL(_xhr);
var status = _xhr.status === 1223 ? 204 : _xhr.status;
if (status === 0) {
status = body ? 200 : 0;
}
var responseOptions = new base_response_options_1.ResponseOptions({
body: body,
status: status,
headers: headers,
url: url
});
if (lang_1.isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}
var response = new static_response_1.Response(responseOptions);
if (http_utils_1.isSuccess(status)) {
responseObserver.next(response);
responseObserver.complete();
return ;
}
responseObserver.error(response);
};
var onError = function(err) {
var responseOptions = new base_response_options_1.ResponseOptions({
body: err,
type: enums_1.ResponseType.Error
});
if (lang_1.isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}
responseObserver.error(new static_response_1.Response(responseOptions));
};
if (lang_1.isPresent(req.headers)) {
req.headers.forEach(function(values, name) {
return _xhr.setRequestHeader(name, values.join(','));
});
}
_xhr.addEventListener('load', onLoad);
_xhr.addEventListener('error', onError);
_xhr.send(_this.request.text());
return function() {
_xhr.removeEventListener('load', onLoad);
_xhr.removeEventListener('error', onError);
_xhr.abort();
};
});
}
return XHRConnection;
}());
exports.XHRConnection = XHRConnection;
var XHRBackend = (function() {
function XHRBackend(_browserXHR, _baseResponseOptions) {
this._browserXHR = _browserXHR;
this._baseResponseOptions = _baseResponseOptions;
}
XHRBackend.prototype.createConnection = function(request) {
return new XHRConnection(request, this._browserXHR, this._baseResponseOptions);
};
XHRBackend = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [browser_xhr_1.BrowserXhr, base_response_options_1.ResponseOptions])], XHRBackend);
return XHRBackend;
}());
exports.XHRBackend = XHRBackend;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/backends/jsonp_backend", ["angular2/src/http/interfaces", "angular2/src/http/enums", "angular2/src/http/static_response", "angular2/src/http/base_response_options", "angular2/core", "angular2/src/http/backends/browser_jsonp", "angular2/src/facade/exceptions", "angular2/src/facade/lang", "rxjs/Observable"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var __extends = (this && this.__extends) || function(d, b) {
for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p];
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var interfaces_1 = require("angular2/src/http/interfaces");
var enums_1 = require("angular2/src/http/enums");
var static_response_1 = require("angular2/src/http/static_response");
var base_response_options_1 = require("angular2/src/http/base_response_options");
var core_1 = require("angular2/core");
var browser_jsonp_1 = require("angular2/src/http/backends/browser_jsonp");
var exceptions_1 = require("angular2/src/facade/exceptions");
var lang_1 = require("angular2/src/facade/lang");
var Observable_1 = require("rxjs/Observable");
var JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
var JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';
var JSONPConnection = (function() {
function JSONPConnection() {}
return JSONPConnection;
}());
exports.JSONPConnection = JSONPConnection;
var JSONPConnection_ = (function(_super) {
__extends(JSONPConnection_, _super);
function JSONPConnection_(req, _dom, baseResponseOptions) {
var _this = this;
_super.call(this);
this._dom = _dom;
this.baseResponseOptions = baseResponseOptions;
this._finished = false;
if (req.method !== enums_1.RequestMethod.Get) {
throw exceptions_1.makeTypeError(JSONP_ERR_WRONG_METHOD);
}
this.request = req;
this.response = new Observable_1.Observable(function(responseObserver) {
_this.readyState = enums_1.ReadyState.Loading;
var id = _this._id = _dom.nextRequestID();
_dom.exposeConnection(id, _this);
var callback = _dom.requestCallback(_this._id);
var url = req.url;
if (url.indexOf('=JSONP_CALLBACK&') > -1) {
url = lang_1.StringWrapper.replace(url, '=JSONP_CALLBACK&', "=" + callback + "&");
} else if (url.lastIndexOf('=JSONP_CALLBACK') === url.length - '=JSONP_CALLBACK'.length) {
url = url.substring(0, url.length - '=JSONP_CALLBACK'.length) + ("=" + callback);
}
var script = _this._script = _dom.build(url);
var onLoad = function(event) {
if (_this.readyState === enums_1.ReadyState.Cancelled)
return ;
_this.readyState = enums_1.ReadyState.Done;
_dom.cleanup(script);
if (!_this._finished) {
var responseOptions_1 = new base_response_options_1.ResponseOptions({
body: JSONP_ERR_NO_CALLBACK,
type: enums_1.ResponseType.Error,
url: url
});
if (lang_1.isPresent(baseResponseOptions)) {
responseOptions_1 = baseResponseOptions.merge(responseOptions_1);
}
responseObserver.error(new static_response_1.Response(responseOptions_1));
return ;
}
var responseOptions = new base_response_options_1.ResponseOptions({
body: _this._responseData,
url: url
});
if (lang_1.isPresent(_this.baseResponseOptions)) {
responseOptions = _this.baseResponseOptions.merge(responseOptions);
}
responseObserver.next(new static_response_1.Response(responseOptions));
responseObserver.complete();
};
var onError = function(error) {
if (_this.readyState === enums_1.ReadyState.Cancelled)
return ;
_this.readyState = enums_1.ReadyState.Done;
_dom.cleanup(script);
var responseOptions = new base_response_options_1.ResponseOptions({
body: error.message,
type: enums_1.ResponseType.Error
});
if (lang_1.isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}
responseObserver.error(new static_response_1.Response(responseOptions));
};
script.addEventListener('load', onLoad);
script.addEventListener('error', onError);
_dom.send(script);
return function() {
_this.readyState = enums_1.ReadyState.Cancelled;
script.removeEventListener('load', onLoad);
script.removeEventListener('error', onError);
if (lang_1.isPresent(script)) {
_this._dom.cleanup(script);
}
};
});
}
JSONPConnection_.prototype.finished = function(data) {
this._finished = true;
this._dom.removeConnection(this._id);
if (this.readyState === enums_1.ReadyState.Cancelled)
return ;
this._responseData = data;
};
return JSONPConnection_;
}(JSONPConnection));
exports.JSONPConnection_ = JSONPConnection_;
var JSONPBackend = (function(_super) {
__extends(JSONPBackend, _super);
function JSONPBackend() {
_super.apply(this, arguments);
}
return JSONPBackend;
}(interfaces_1.ConnectionBackend));
exports.JSONPBackend = JSONPBackend;
var JSONPBackend_ = (function(_super) {
__extends(JSONPBackend_, _super);
function JSONPBackend_(_browserJSONP, _baseResponseOptions) {
_super.call(this);
this._browserJSONP = _browserJSONP;
this._baseResponseOptions = _baseResponseOptions;
}
JSONPBackend_.prototype.createConnection = function(request) {
return new JSONPConnection_(request, this._browserJSONP, this._baseResponseOptions);
};
JSONPBackend_ = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [browser_jsonp_1.BrowserJsonp, base_response_options_1.ResponseOptions])], JSONPBackend_);
return JSONPBackend_;
}(JSONPBackend));
exports.JSONPBackend_ = JSONPBackend_;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/static_request", ["angular2/src/http/headers", "angular2/src/http/http_utils", "angular2/src/facade/lang"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var headers_1 = require("angular2/src/http/headers");
var http_utils_1 = require("angular2/src/http/http_utils");
var lang_1 = require("angular2/src/facade/lang");
var Request = (function() {
function Request(requestOptions) {
var url = requestOptions.url;
this.url = requestOptions.url;
if (lang_1.isPresent(requestOptions.search)) {
var search = requestOptions.search.toString();
if (search.length > 0) {
var prefix = '?';
if (lang_1.StringWrapper.contains(this.url, '?')) {
prefix = (this.url[this.url.length - 1] == '&') ? '' : '&';
}
this.url = url + prefix + search;
}
}
this._body = requestOptions.body;
this.method = http_utils_1.normalizeMethodName(requestOptions.method);
this.headers = new headers_1.Headers(requestOptions.headers);
}
Request.prototype.text = function() {
return lang_1.isPresent(this._body) ? this._body.toString() : '';
};
return Request;
}());
exports.Request = Request;
global.define = __define;
return module.exports;
});
System.register("angular2/src/http/http", ["angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/core", "angular2/src/http/interfaces", "angular2/src/http/static_request", "angular2/src/http/base_request_options", "angular2/src/http/enums"], true, function(require, exports, module) {
var global = System.global,
__define = global.define;
global.define = undefined;
"use strict";
var __extends = (this && this.__extends) || function(d, b) {
for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p];
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(k, v);
};
var lang_1 = require("angular2/src/facade/lang");
var exceptions_1 = require("angular2/src/facade/exceptions");
var core_1 = require("angular2/core");
var interfaces_1 = require("angular2/src/http/interfaces");
var static_request_1 = require("angular2/src/http/static_request");
var base_request_options_1 = require("angular2/src/http/base_request_options");
var enums_1 = require("angular2/src/http/enums");
function httpRequest(backend, request) {
return backend.createConnection(request).response;
}
function mergeOptions(defaultOpts, providedOpts, method, url) {
var newOptions = defaultOpts;
if (lang_1.isPresent(providedOpts)) {
return newOptions.merge(new base_request_options_1.RequestOptions({
method: providedOpts.method || method,
url: providedOpts.url || url,
search: providedOpts.search,
headers: providedOpts.headers,
body: providedOpts.body
}));
}
if (lang_1.isPresent(method)) {
return newOptions.merge(new base_request_options_1.RequestOptions({
method: method,
url: url
}));
} else {
return newOptions.merge(new base_request_options_1.RequestOptions({url: url}));
}
}
var Http = (function() {
function Http(_backend, _defaultOptions) {
this._backend = _backend;
this._defaultOptions = _defaultOptions;
}
Http.prototype.request = function(url, options) {
var responseObservable;
if (lang_1.isString(url)) {
responseObservable = httpRequest(this._backend, new static_request_1.Request(mergeOptions(this._defaultOptions, options, enums_1.RequestMethod.Get, url)));
} else if (url instanceof static_request_1.Request) {
responseObservable = httpRequest(this._backend, url);
} else {
throw exceptions_1.makeTypeError('First argument must be a url string or Request instance.');
}
return responseObservable;
};
Http.prototype.get = function(url, options) {
return httpRequest(this._backend, new static_request_1.Request(mergeOptions(this._defaultOptions, options, enums_1.RequestMethod.Get, url)));
};
Http.prototype.post = function(url, body, options) {
return httpRequest(this._backend, new static_request_1.Request(mergeOptions(this._defaultOptions.merge(new base_request_options_1.RequestOptions({body: body})), options, enums_1.RequestMethod.Post, url)));
};
Http.prototype.put = function(url, body, options) {
return httpRequest(this._backend, new static_request_1.Request(mergeOptions(this._defaultOptions.merge(new base_request_options_1.RequestOptions({body: body})), options, enums_1.RequestMethod.Put, url)));