2015-11-06 20:34:07 -05:00
|
|
|
import {isString} from 'angular2/src/facade/lang';
|
2015-09-21 03:46:16 -04:00
|
|
|
import {RequestMethods} from './enums';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {makeTypeError} from 'angular2/src/facade/exceptions';
|
2015-11-19 20:29:41 -05:00
|
|
|
import {Response} from './static_response';
|
2015-09-21 03:46:16 -04:00
|
|
|
|
|
|
|
export function normalizeMethodName(method): RequestMethods {
|
|
|
|
if (isString(method)) {
|
|
|
|
var originalMethod = method;
|
|
|
|
method = method.replace(/(\w)(\w*)/g, (g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase());
|
|
|
|
method = RequestMethods[method];
|
|
|
|
if (typeof method !== 'number')
|
|
|
|
throw makeTypeError(
|
|
|
|
`Invalid request method. The method "${originalMethod}" is not supported.`);
|
|
|
|
}
|
|
|
|
return method;
|
|
|
|
}
|
|
|
|
|
2015-11-19 20:29:41 -05:00
|
|
|
export const isSuccess = (status: number): boolean => (status >= 200 && status < 300);
|
|
|
|
|
2015-11-19 21:47:29 -05: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;
|
|
|
|
}
|
|
|
|
|
2015-11-06 20:34:07 -05:00
|
|
|
export {isJsObject} from 'angular2/src/facade/lang';
|