mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
b925ff5b8d
ReadyStates -> ReadyState RequestMethods -> RequestMethod ResponseTypes -> ResponseType Fixes #5574 BREAKING CHANGE: Before import {ReadyStates, RequestMethods, ResponseTypes} from 'angular2/http'; After import {ReadyState, RequestMethod, ResponseType} from 'angular2/http'; Closes #5584
31 lines
1007 B
TypeScript
31 lines
1007 B
TypeScript
import {isString} from 'angular2/src/facade/lang';
|
|
import {RequestMethod} from './enums';
|
|
import {makeTypeError} from 'angular2/src/facade/exceptions';
|
|
import {Response} from './static_response';
|
|
|
|
export function normalizeMethodName(method): RequestMethod {
|
|
if (isString(method)) {
|
|
var originalMethod = method;
|
|
method = method.replace(/(\w)(\w*)/g, (g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase());
|
|
method = RequestMethod[method];
|
|
if (typeof method !== 'number')
|
|
throw makeTypeError(
|
|
`Invalid request method. The method "${originalMethod}" is not supported.`);
|
|
}
|
|
return method;
|
|
}
|
|
|
|
export const isSuccess = (status: number): boolean => (status >= 200 && status < 300);
|
|
|
|
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 'angular2/src/facade/lang';
|