2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2015-12-03 22:44:14 +01:00
|
|
|
import {RequestMethod} from './enums';
|
2015-09-21 10:46:16 +03:00
|
|
|
|
2016-02-01 17:05:50 -08:00
|
|
|
export function normalizeMethodName(method: string | RequestMethod): RequestMethod {
|
2016-10-19 13:42:39 -07:00
|
|
|
if (typeof method !== 'string') return method;
|
|
|
|
|
2016-10-18 11:21:54 -07:00
|
|
|
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;
|
2015-09-21 10:46:16 +03:00
|
|
|
}
|
2016-10-18 11:21:54 -07:00
|
|
|
throw new Error(`Invalid request method. The method "${method}" is not supported.`);
|
2015-09-21 10:46:16 +03:00
|
|
|
}
|
|
|
|
|
2015-11-19 17:29:41 -08:00
|
|
|
export const isSuccess = (status: number): boolean => (status >= 200 && status < 300);
|
|
|
|
|
2015-11-19 18:47:29 -08:00
|
|
|
export function getResponseURL(xhr: any): string {
|
|
|
|
if ('responseURL' in xhr) {
|
|
|
|
return xhr.responseURL;
|
|
|
|
}
|
|
|
|
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
|
|
|
|
return xhr.getResponseHeader('X-Request-URL');
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-27 00:47:20 +02:00
|
|
|
export function stringToArrayBuffer(input: String): ArrayBuffer {
|
|
|
|
let view = new Uint16Array(input.length);
|
|
|
|
for (var i = 0, strLen = input.length; i < strLen; i++) {
|
|
|
|
view[i] = input.charCodeAt(i);
|
2016-02-24 16:37:18 +01:00
|
|
|
}
|
|
|
|
return view.buffer;
|
|
|
|
}
|
|
|
|
|
2016-04-28 17:50:03 -07:00
|
|
|
export {isJsObject} from '../src/facade/lang';
|