http_utils.js
1.67 KB
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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { RequestMethod } from './enums';
/**
* @param {?} method
* @return {?}
*/
export function normalizeMethodName(method) {
if (typeof method !== 'string')
return method;
switch (method.toUpperCase()) {
case 'GET':
return RequestMethod.Get;
case 'POST':
return RequestMethod.Post;
case 'PUT':
return RequestMethod.Put;
case 'DELETE':
return RequestMethod.Delete;
case 'OPTIONS':
return RequestMethod.Options;
case 'HEAD':
return RequestMethod.Head;
case 'PATCH':
return RequestMethod.Patch;
}
throw new Error("Invalid request method. The method \"" + method + "\" is not supported.");
}
export var /** @type {?} */ isSuccess = function (status) { return (status >= 200 && status < 300); };
/**
* @param {?} xhr
* @return {?}
*/
export 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;
}
/**
* @param {?} input
* @return {?}
*/
export function stringToArrayBuffer(input) {
var /** @type {?} */ view = new Uint16Array(input.length);
for (var /** @type {?} */ i = 0, /** @type {?} */ strLen = input.length; i < strLen; i++) {
view[i] = input.charCodeAt(i);
}
return view.buffer;
}
//# sourceMappingURL=http_utils.js.map