Files
angular-docs-cn/modules/@angular/http/src/http_utils.ts
T

32 lines
1.1 KiB
TypeScript
Raw Normal View History

import {isString} from '../src/facade/lang';
2015-12-03 22:44:14 +01:00
import {RequestMethod} from './enums';
import {makeTypeError} from '../src/facade/exceptions';
2016-02-01 17:05:50 -08:00
export function normalizeMethodName(method: string | RequestMethod): RequestMethod {
if (isString(method)) {
var originalMethod = method;
2016-02-01 17:05:50 -08:00
method = (<string>method)
.replace(/(\w)(\w*)/g, (g0: string, g1: string, g2: string) =>
g1.toUpperCase() + g2.toLowerCase());
2016-02-01 17:05:50 -08:00
method = <number>(<{[key: string]: any}>RequestMethod)[method];
if (typeof method !== 'number')
throw makeTypeError(
`Invalid request method. The method "${originalMethod}" is not supported.`);
}
2016-02-01 17:05:50 -08:00
return <RequestMethod>method;
}
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;
}
export {isJsObject} from '../src/facade/lang';