style(lint): re-format modules/@angular
This commit is contained in:
@ -5,37 +5,30 @@
|
||||
* class.
|
||||
*/
|
||||
import {provide} from '@angular/core';
|
||||
import {Http, Jsonp} from './src/http';
|
||||
import {XHRBackend, XHRConnection, CookieXSRFStrategy} from './src/backends/xhr_backend';
|
||||
import {JSONPBackend, JSONPBackend_, JSONPConnection} from './src/backends/jsonp_backend';
|
||||
import {BrowserXhr} from './src/backends/browser_xhr';
|
||||
import {BrowserJsonp} from './src/backends/browser_jsonp';
|
||||
import {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
||||
import {ConnectionBackend, XSRFStrategy} from './src/interfaces';
|
||||
import {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
||||
export {Request} from './src/static_request';
|
||||
export {Response} from './src/static_response';
|
||||
|
||||
export {
|
||||
RequestOptionsArgs,
|
||||
ResponseOptionsArgs,
|
||||
Connection,
|
||||
ConnectionBackend,
|
||||
XSRFStrategy
|
||||
} from './src/interfaces';
|
||||
import {BrowserJsonp} from './src/backends/browser_jsonp';
|
||||
import {BrowserXhr} from './src/backends/browser_xhr';
|
||||
import {JSONPBackend, JSONPBackend_, JSONPConnection} from './src/backends/jsonp_backend';
|
||||
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from './src/backends/xhr_backend';
|
||||
import {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
||||
import {Http, Jsonp} from './src/http';
|
||||
import {ConnectionBackend, XSRFStrategy} from './src/interfaces';
|
||||
|
||||
export {BrowserXhr} from './src/backends/browser_xhr';
|
||||
export {JSONPBackend, JSONPConnection} from './src/backends/jsonp_backend';
|
||||
export {CookieXSRFStrategy, XHRBackend, XHRConnection} from './src/backends/xhr_backend';
|
||||
export {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
||||
export {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
||||
export {XHRBackend, XHRConnection, CookieXSRFStrategy} from './src/backends/xhr_backend';
|
||||
export {JSONPBackend, JSONPConnection} from './src/backends/jsonp_backend';
|
||||
export {Http, Jsonp} from './src/http';
|
||||
|
||||
export {ReadyState, RequestMethod, ResponseType} from './src/enums';
|
||||
export {Headers} from './src/headers';
|
||||
|
||||
export {ResponseType, ReadyState, RequestMethod} from './src/enums';
|
||||
export {Http, Jsonp} from './src/http';
|
||||
export {Connection, ConnectionBackend, RequestOptionsArgs, ResponseOptionsArgs, XSRFStrategy} from './src/interfaces';
|
||||
export {Request} from './src/static_request';
|
||||
export {Response} from './src/static_response';
|
||||
export {URLSearchParams} from './src/url_search_params';
|
||||
|
||||
|
||||
/**
|
||||
* Provides a basic set of injectables to use the {@link Http} service in any application.
|
||||
*
|
||||
@ -182,7 +175,7 @@ export {URLSearchParams} from './src/url_search_params';
|
||||
export const HTTP_PROVIDERS: any[] = [
|
||||
// TODO(pascal): use factory type annotations once supported in DI
|
||||
// issue: https://github.com/angular/angular/issues/3183
|
||||
{ provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
|
||||
{provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
|
||||
BrowserXhr,
|
||||
{provide: RequestOptions, useClass: BaseRequestOptions},
|
||||
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||
|
@ -1,15 +1,17 @@
|
||||
import {ConnectionBackend, Connection} from '../interfaces';
|
||||
import {ReadyState, RequestMethod, ResponseType} from '../enums';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
import {ResponseOptions, BaseResponseOptions} from '../base_response_options';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BrowserJsonp} from './browser_jsonp';
|
||||
import {makeTypeError} from '../facade/exceptions';
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
|
||||
import {BaseResponseOptions, ResponseOptions} from '../base_response_options';
|
||||
import {ReadyState, RequestMethod, ResponseType} from '../enums';
|
||||
import {makeTypeError} from '../facade/exceptions';
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {Connection, ConnectionBackend} from '../interfaces';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
|
||||
import {BrowserJsonp} from './browser_jsonp';
|
||||
|
||||
const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
|
||||
const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';
|
||||
|
||||
@ -45,8 +47,8 @@ export class JSONPConnection_ extends JSONPConnection {
|
||||
private _responseData: any;
|
||||
private _finished: boolean = false;
|
||||
|
||||
constructor(req: Request, private _dom: BrowserJsonp,
|
||||
private baseResponseOptions?: ResponseOptions) {
|
||||
constructor(
|
||||
req: Request, private _dom: BrowserJsonp, private baseResponseOptions?: ResponseOptions) {
|
||||
super();
|
||||
if (req.method !== RequestMethod.Get) {
|
||||
throw makeTypeError(JSONP_ERR_WRONG_METHOD);
|
||||
|
@ -1,17 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {__platform_browser_private__} from '@angular/platform-browser';
|
||||
|
||||
import {ConnectionBackend, Connection, XSRFStrategy} from '../interfaces';
|
||||
import {ReadyState, RequestMethod, ResponseType, ContentType} from '../enums';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
import {Headers} from '../headers';
|
||||
import {ResponseOptions} from '../base_response_options';
|
||||
import {BrowserXhr} from './browser_xhr';
|
||||
import {isPresent, isString} from '../facade/lang';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
import {isSuccess, getResponseURL} from '../http_utils';
|
||||
|
||||
import {ResponseOptions} from '../base_response_options';
|
||||
import {ContentType, ReadyState, RequestMethod, ResponseType} from '../enums';
|
||||
import {isPresent, isString} from '../facade/lang';
|
||||
import {Headers} from '../headers';
|
||||
import {getResponseURL, isSuccess} from '../http_utils';
|
||||
import {Connection, ConnectionBackend, XSRFStrategy} from '../interfaces';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
|
||||
import {BrowserXhr} from './browser_xhr';
|
||||
|
||||
const XSSI_PREFIX = /^\)\]\}',?\n/;
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
import {isPresent, isString} from '../src/facade/lang';
|
||||
import {Headers} from './headers';
|
||||
import {RequestMethod} from './enums';
|
||||
import {RequestOptionsArgs} from './interfaces';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
|
||||
import {isPresent, isString} from '../src/facade/lang';
|
||||
|
||||
import {RequestMethod} from './enums';
|
||||
import {Headers} from './headers';
|
||||
import {normalizeMethodName} from './http_utils';
|
||||
import {RequestOptionsArgs} from './interfaces';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
|
||||
|
||||
/**
|
||||
* Creates a request options object to be optionally provided when instantiating a
|
||||
@ -35,7 +38,7 @@ export class RequestOptions {
|
||||
* Http method with which to execute a {@link Request}.
|
||||
* Acceptable methods are defined in the {@link RequestMethod} enum.
|
||||
*/
|
||||
method: RequestMethod | string;
|
||||
method: RequestMethod|string;
|
||||
/**
|
||||
* {@link Headers} to be attached to a {@link Request}.
|
||||
*/
|
||||
@ -61,9 +64,9 @@ export class RequestOptions {
|
||||
this.headers = isPresent(headers) ? headers : null;
|
||||
this.body = isPresent(body) ? body : null;
|
||||
this.url = isPresent(url) ? url : null;
|
||||
this.search = isPresent(search) ? (isString(search) ? new URLSearchParams(<string>(search)) :
|
||||
<URLSearchParams>(search)) :
|
||||
null;
|
||||
this.search = isPresent(search) ?
|
||||
(isString(search) ? new URLSearchParams(<string>(search)) : <URLSearchParams>(search)) :
|
||||
null;
|
||||
this.withCredentials = isPresent(withCredentials) ? withCredentials : null;
|
||||
}
|
||||
|
||||
@ -99,12 +102,12 @@ export class RequestOptions {
|
||||
body: isPresent(options) && isPresent(options.body) ? options.body : this.body,
|
||||
url: isPresent(options) && isPresent(options.url) ? options.url : this.url,
|
||||
search: isPresent(options) && isPresent(options.search) ?
|
||||
(isString(options.search) ? new URLSearchParams(<string>(options.search)) :
|
||||
(<URLSearchParams>(options.search)).clone()) :
|
||||
this.search,
|
||||
(isString(options.search) ? new URLSearchParams(<string>(options.search)) :
|
||||
(<URLSearchParams>(options.search)).clone()) :
|
||||
this.search,
|
||||
withCredentials: isPresent(options) && isPresent(options.withCredentials) ?
|
||||
options.withCredentials :
|
||||
this.withCredentials
|
||||
options.withCredentials :
|
||||
this.withCredentials
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {isPresent, isJsObject} from '../src/facade/lang';
|
||||
import {Headers} from './headers';
|
||||
|
||||
import {isJsObject, isPresent} from '../src/facade/lang';
|
||||
|
||||
import {ResponseType} from './enums';
|
||||
import {Headers} from './headers';
|
||||
import {ResponseOptionsArgs} from './interfaces';
|
||||
|
||||
|
||||
/**
|
||||
* Creates a response options object to be optionally provided when instantiating a
|
||||
* {@link Response}.
|
||||
@ -35,7 +38,7 @@ export class ResponseOptions {
|
||||
/**
|
||||
* String or Object representing the body of the {@link Response}.
|
||||
*/
|
||||
body: string | Object;
|
||||
body: string|Object;
|
||||
/**
|
||||
* Http {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html status code}
|
||||
* associated with the response.
|
||||
|
@ -1,13 +1,7 @@
|
||||
import {isBlank} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {
|
||||
isListLikeIterable,
|
||||
iterateListLike,
|
||||
Map,
|
||||
MapWrapper,
|
||||
StringMapWrapper,
|
||||
ListWrapper,
|
||||
} from '../src/facade/collection';
|
||||
import {isBlank} from '../src/facade/lang';
|
||||
|
||||
import {isListLikeIterable, iterateListLike, Map, MapWrapper, StringMapWrapper, ListWrapper,} from '../src/facade/collection';
|
||||
|
||||
/**
|
||||
* Polyfill for [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers), as
|
||||
@ -38,7 +32,7 @@ import {
|
||||
export class Headers {
|
||||
/** @internal */
|
||||
_headersMap: Map<string, string[]>;
|
||||
constructor(headers?: Headers | {[key: string]: any}) {
|
||||
constructor(headers?: Headers|{[key: string]: any}) {
|
||||
if (headers instanceof Headers) {
|
||||
this._headersMap = (<Headers>headers)._headersMap;
|
||||
return;
|
||||
@ -104,7 +98,7 @@ export class Headers {
|
||||
/**
|
||||
* Sets or overrides header value for given name.
|
||||
*/
|
||||
set(header: string, value: string | string[]): void {
|
||||
set(header: string, value: string|string[]): void {
|
||||
var list: string[] = [];
|
||||
|
||||
if (isListLikeIterable(value)) {
|
||||
@ -130,7 +124,8 @@ export class Headers {
|
||||
this._headersMap.forEach((values: string[], name: string) => {
|
||||
let list: any[] /** TODO #9100 */ = [];
|
||||
|
||||
iterateListLike(values, (val: any /** TODO #9100 */) => list = ListWrapper.concat(list, val.split(',')));
|
||||
iterateListLike(
|
||||
values, (val: any /** TODO #9100 */) => list = ListWrapper.concat(list, val.split(',')));
|
||||
|
||||
(serializableHeaders as any /** TODO #9100 */)[name] = list;
|
||||
});
|
||||
|
@ -1,20 +1,23 @@
|
||||
import {isString, isPresent} from '../src/facade/lang';
|
||||
import {makeTypeError} from '../src/facade/exceptions';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {RequestOptionsArgs, ConnectionBackend} from './interfaces';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
import {makeTypeError} from '../src/facade/exceptions';
|
||||
import {isPresent, isString} from '../src/facade/lang';
|
||||
|
||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
import {RequestMethod} from './enums';
|
||||
import {ConnectionBackend, RequestOptionsArgs} from './interfaces';
|
||||
import {Request} from './static_request';
|
||||
import {Response} from './static_response';
|
||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
import {RequestMethod} from './enums';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
function httpRequest(backend: ConnectionBackend, request: Request): Observable<Response> {
|
||||
return backend.createConnection(request).response;
|
||||
}
|
||||
|
||||
function mergeOptions(defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs,
|
||||
method: RequestMethod, url: string): RequestOptions {
|
||||
function mergeOptions(
|
||||
defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs, method: RequestMethod,
|
||||
url: string): RequestOptions {
|
||||
var newOptions = defaultOpts;
|
||||
if (isPresent(providedOpts)) {
|
||||
// Hack so Dart can used named parameters
|
||||
@ -103,7 +106,7 @@ export class Http {
|
||||
* object can be provided as the 2nd argument. The options object will be merged with the values
|
||||
* of {@link BaseRequestOptions} before performing the request.
|
||||
*/
|
||||
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
request(url: string|Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
var responseObservable: any;
|
||||
if (isString(url)) {
|
||||
responseObservable = httpRequest(
|
||||
@ -121,8 +124,9 @@ export class Http {
|
||||
* Performs a request with `get` http method.
|
||||
*/
|
||||
get(url: string, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethod.Get, url)));
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,9 +134,9 @@ export class Http {
|
||||
*/
|
||||
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
options, RequestMethod.Post, url)));
|
||||
this._backend, new Request(mergeOptions(
|
||||
this._defaultOptions.merge(new RequestOptions({body: body})), options,
|
||||
RequestMethod.Post, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,17 +144,18 @@ export class Http {
|
||||
*/
|
||||
put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
options, RequestMethod.Put, url)));
|
||||
this._backend, new Request(mergeOptions(
|
||||
this._defaultOptions.merge(new RequestOptions({body: body})), options,
|
||||
RequestMethod.Put, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a request with `delete` http method.
|
||||
*/
|
||||
delete (url: string, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethod.Delete, url)));
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Delete, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,17 +163,18 @@ export class Http {
|
||||
*/
|
||||
patch(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
options, RequestMethod.Patch, url)));
|
||||
this._backend, new Request(mergeOptions(
|
||||
this._defaultOptions.merge(new RequestOptions({body: body})), options,
|
||||
RequestMethod.Patch, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a request with `head` http method.
|
||||
*/
|
||||
head(url: string, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethod.Head, url)));
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Head, url)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,7 +190,7 @@ export class Jsonp extends Http {
|
||||
* object can be provided as the 2nd argument. The options object will be merged with the values
|
||||
* of {@link BaseRequestOptions} before performing the request.
|
||||
*/
|
||||
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
request(url: string|Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
var responseObservable: any;
|
||||
if (isString(url)) {
|
||||
url =
|
||||
|
@ -1,13 +1,15 @@
|
||||
import {isString} from '../src/facade/lang';
|
||||
import {RequestMethod} from './enums';
|
||||
import {makeTypeError} from '../src/facade/exceptions';
|
||||
import {isString} from '../src/facade/lang';
|
||||
|
||||
import {RequestMethod} from './enums';
|
||||
|
||||
export function normalizeMethodName(method: string | RequestMethod): RequestMethod {
|
||||
if (isString(method)) {
|
||||
var originalMethod = method;
|
||||
method = (<string>method)
|
||||
.replace(/(\w)(\w*)/g, (g0: string, g1: string, g2: string) =>
|
||||
g1.toUpperCase() + g2.toLowerCase());
|
||||
.replace(
|
||||
/(\w)(\w*)/g,
|
||||
(g0: string, g1: string, g2: string) => g1.toUpperCase() + g2.toLowerCase());
|
||||
method = <number>(<{[key: string]: any}>RequestMethod)[method];
|
||||
if (typeof method !== 'number')
|
||||
throw makeTypeError(
|
||||
|
@ -21,9 +21,7 @@ export abstract class Connection {
|
||||
}
|
||||
|
||||
/** An XSRFStrategy configures XSRF protection (e.g. via headers) on an HTTP request. */
|
||||
export abstract class XSRFStrategy {
|
||||
abstract configureRequest(req: Request): void;
|
||||
}
|
||||
export abstract class XSRFStrategy { abstract configureRequest(req: Request): void; }
|
||||
|
||||
/**
|
||||
* Interface for options to construct a RequestOptions, based on
|
||||
@ -31,8 +29,8 @@ export abstract class XSRFStrategy {
|
||||
*/
|
||||
export interface RequestOptionsArgs {
|
||||
url?: string;
|
||||
method?: string | RequestMethod;
|
||||
search?: string | URLSearchParams;
|
||||
method?: string|RequestMethod;
|
||||
search?: string|URLSearchParams;
|
||||
headers?: Headers;
|
||||
body?: any;
|
||||
withCredentials?: boolean;
|
||||
@ -49,10 +47,7 @@ export interface RequestArgs extends RequestOptionsArgs { url: string; }
|
||||
*/
|
||||
export type ResponseOptionsArgs = {
|
||||
// TODO: Support Blob, ArrayBuffer, JSON
|
||||
body?: string | Object | FormData;
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
headers?: Headers;
|
||||
body?: string | Object | FormData; status?: number; statusText?: string; headers?: Headers;
|
||||
type?: ResponseType;
|
||||
url?: string;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import {StringWrapper, isPresent} from '../src/facade/lang';
|
||||
|
||||
import {ContentType, RequestMethod} from './enums';
|
||||
import {RequestArgs} from './interfaces';
|
||||
import {Headers} from './headers';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
import {normalizeMethodName} from './http_utils';
|
||||
import {isPresent, StringWrapper} from '../src/facade/lang';
|
||||
import {RequestArgs} from './interfaces';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
|
||||
|
||||
// TODO(jeffbcross): properly implement body accessors
|
||||
/**
|
||||
@ -108,7 +110,7 @@ export class Request {
|
||||
*/
|
||||
arrayBuffer(): ArrayBuffer {
|
||||
if (this._body instanceof ArrayBuffer) return <ArrayBuffer>this._body;
|
||||
throw "The request body isn't an array buffer";
|
||||
throw 'The request body isn\'t an array buffer';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +120,7 @@ export class Request {
|
||||
blob(): Blob {
|
||||
if (this._body instanceof Blob) return <Blob>this._body;
|
||||
if (this._body instanceof ArrayBuffer) return new Blob([this._body]);
|
||||
throw "The request body isn't either a blob or an array buffer";
|
||||
throw 'The request body isn\'t either a blob or an array buffer';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +168,7 @@ export class Request {
|
||||
}
|
||||
}
|
||||
|
||||
const noop = function () {};
|
||||
const noop = function() {};
|
||||
const w = typeof window == 'object' ? window : noop;
|
||||
const FormData = (w as any /** TODO #9100 */)['FormData'] || noop;
|
||||
const Blob = (w as any /** TODO #9100 */)['Blob'] || noop;
|
||||
|
@ -1,10 +1,12 @@
|
||||
import {ResponseType} from './enums';
|
||||
import {isString, Json} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {Headers} from './headers';
|
||||
import {Json, isString} from '../src/facade/lang';
|
||||
|
||||
import {ResponseOptions} from './base_response_options';
|
||||
import {ResponseType} from './enums';
|
||||
import {Headers} from './headers';
|
||||
import {isJsObject} from './http_utils';
|
||||
|
||||
|
||||
/**
|
||||
* Creates `Response` instances from provided values.
|
||||
*
|
||||
@ -72,7 +74,7 @@ export class Response {
|
||||
*/
|
||||
headers: Headers;
|
||||
// TODO: Support ArrayBuffer, JSON, FormData, Blob
|
||||
private _body: string | Object;
|
||||
private _body: string|Object;
|
||||
constructor(responseOptions: ResponseOptions) {
|
||||
this._body = responseOptions.body;
|
||||
this.status = responseOptions.status;
|
||||
@ -93,7 +95,7 @@ export class Response {
|
||||
* Attempts to return body as parsed `JSON` object, or raises an exception.
|
||||
*/
|
||||
json(): any {
|
||||
var jsonResponse: string | Object;
|
||||
var jsonResponse: string|Object;
|
||||
if (isJsObject(this._body)) {
|
||||
jsonResponse = this._body;
|
||||
} else if (isString(this._body)) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {ListWrapper, Map, isListLikeIterable} from '../src/facade/collection';
|
||||
import {isPresent} from '../src/facade/lang';
|
||||
import {Map, ListWrapper, isListLikeIterable} from '../src/facade/collection';
|
||||
|
||||
function paramParser(rawParams: string = ''): Map<string, string[]> {
|
||||
var map = new Map<string, string[]>();
|
||||
|
@ -1,23 +1,8 @@
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter, SpyObject} from '@angular/core/testing/testing_internal';
|
||||
import {ObservableWrapper} from '../../src/facade/async';
|
||||
import {BrowserJsonp} from '../../src/backends/browser_jsonp';
|
||||
import {
|
||||
JSONPConnection,
|
||||
JSONPConnection_,
|
||||
JSONPBackend,
|
||||
JSONPBackend_
|
||||
} from '../../src/backends/jsonp_backend';
|
||||
import {JSONPConnection, JSONPConnection_, JSONPBackend, JSONPBackend_} from '../../src/backends/jsonp_backend';
|
||||
import {provide, Injector, ReflectiveInjector} from '@angular/core';
|
||||
import {isPresent, StringWrapper} from '../../src/facade/lang';
|
||||
import {TimerWrapper} from '../../src/facade/async';
|
||||
@ -92,8 +77,9 @@ export function main() {
|
||||
describe('JSONPConnection', () => {
|
||||
it('should use the injected BaseResponseOptions to create the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
let connection = new JSONPConnection_(sampleRequest, new MockBrowserJsonp(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
let connection = new JSONPConnection_(
|
||||
sampleRequest, new MockBrowserJsonp(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe(res => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
async.done();
|
||||
@ -130,7 +116,7 @@ export function main() {
|
||||
let connection = new JSONPConnection_(sampleRequest, new MockBrowserJsonp());
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
expect("response listener called").toBe(false);
|
||||
expect('response listener called').toBe(false);
|
||||
async.done();
|
||||
},
|
||||
err => {
|
||||
@ -147,7 +133,7 @@ export function main() {
|
||||
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
expect("response listener called").toBe(false);
|
||||
expect('response listener called').toBe(false);
|
||||
async.done();
|
||||
},
|
||||
err => {
|
||||
@ -155,7 +141,7 @@ export function main() {
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingScripts[0].dispatchEvent('error', ({message: "Oops!"}));
|
||||
existingScripts[0].dispatchEvent('error', ({message: 'Oops!'}));
|
||||
}));
|
||||
|
||||
it('should throw if request method is not GET', () => {
|
||||
|
@ -1,14 +1,4 @@
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {ObservableWrapper} from '../../src/facade/async';
|
||||
import {BrowserXhr} from '../../src/backends/browser_xhr';
|
||||
@ -107,8 +97,8 @@ export function main() {
|
||||
let responseObservable: ReplaySubject<Response> =
|
||||
backend.createConnection(sampleRequest1).response;
|
||||
responseObservable.subscribe(res => expect(res.text()).toBe('response1'));
|
||||
responseObservable.subscribe(res => expect(res.text()).toBe('response2'), null,
|
||||
async.done);
|
||||
responseObservable.subscribe(
|
||||
res => expect(res.text()).toBe('response2'), null, async.done);
|
||||
}));
|
||||
|
||||
// TODO(robwormald): readyStates are leaving?
|
||||
|
@ -1,15 +1,4 @@
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
beforeEachProviders,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter, SpyObject} from '@angular/core/testing/testing_internal';
|
||||
import {BrowserXhr} from '../../src/backends/browser_xhr';
|
||||
import {XSRFStrategy} from '../../src/interfaces';
|
||||
@ -94,11 +83,9 @@ export function main() {
|
||||
|
||||
beforeEachProviders(
|
||||
() =>
|
||||
[
|
||||
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||
{provide: BrowserXhr, useClass: MockBrowserXHR},
|
||||
XHRBackend,
|
||||
{provide: XSRFStrategy, useValue: new CookieXSRFStrategy()},
|
||||
[{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||
{provide: BrowserXhr, useClass: MockBrowserXHR}, XHRBackend,
|
||||
{provide: XSRFStrategy, useValue: new CookieXSRFStrategy()},
|
||||
]);
|
||||
|
||||
beforeEach(inject([XHRBackend], (be: XHRBackend) => {
|
||||
@ -136,8 +123,10 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('configuration', () => {
|
||||
beforeEachProviders(
|
||||
() => [{provide: XSRFStrategy, useValue: new CookieXSRFStrategy('my cookie', 'X-MY-HEADER')}]);
|
||||
beforeEachProviders(() => [{
|
||||
provide: XSRFStrategy,
|
||||
useValue: new CookieXSRFStrategy('my cookie', 'X-MY-HEADER')
|
||||
}]);
|
||||
|
||||
it('uses the configured names', () => {
|
||||
getDOM().setCookie('my cookie', 'XSRF value');
|
||||
@ -151,8 +140,9 @@ export function main() {
|
||||
describe('XHRConnection', () => {
|
||||
it('should use the injected BaseResponseOptions to create the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
async.done();
|
||||
@ -162,11 +152,12 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should complete a request', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
}, null, () => { async.done(); });
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe(
|
||||
(res: Response) => { expect(res.type).toBe(ResponseType.Error); }, null,
|
||||
() => { async.done(); });
|
||||
existingXHRs[0].setStatusCode(200);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
@ -180,8 +171,9 @@ export function main() {
|
||||
|
||||
it('should create an error Response on error',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe(null, (res: Response) => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
async.done();
|
||||
@ -260,8 +252,8 @@ export function main() {
|
||||
connection.response.subscribe();
|
||||
expect(sendSpy).toHaveBeenCalledWith('test1=val1&test2=val2');
|
||||
expect(setRequestHeaderSpy)
|
||||
.toHaveBeenCalledWith('Content-Type',
|
||||
'application/x-www-form-urlencoded;charset=UTF-8');
|
||||
.toHaveBeenCalledWith(
|
||||
'Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
|
||||
});
|
||||
|
||||
if ((global as any /** TODO #9100 */)['Blob']) {
|
||||
@ -270,7 +262,7 @@ export function main() {
|
||||
body.append('test1', 'val1');
|
||||
body.append('test2', 123456);
|
||||
var blob = new Blob(['body { color: red; }'], {type: 'text/css'});
|
||||
body.append("userfile", blob);
|
||||
body.append('userfile', blob);
|
||||
var base = new BaseRequestOptions();
|
||||
var connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||
@ -299,17 +291,18 @@ export function main() {
|
||||
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should use blob body without type with custom content type header to the request', () => {
|
||||
var headers = new Headers({'Content-Type': 'text/css'});
|
||||
var body = new Blob(['body { color: red; }']);
|
||||
var base = new BaseRequestOptions();
|
||||
var connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||
new MockBrowserXHR());
|
||||
connection.response.subscribe();
|
||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/css');
|
||||
});
|
||||
it('should use blob body without type with custom content type header to the request',
|
||||
() => {
|
||||
var headers = new Headers({'Content-Type': 'text/css'});
|
||||
var body = new Blob(['body { color: red; }']);
|
||||
var base = new BaseRequestOptions();
|
||||
var connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||
new MockBrowserXHR());
|
||||
connection.response.subscribe();
|
||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/css');
|
||||
});
|
||||
|
||||
it('should use array buffer body to the request', () => {
|
||||
var body = new ArrayBuffer(512);
|
||||
@ -319,35 +312,35 @@ export function main() {
|
||||
}
|
||||
var base = new BaseRequestOptions();
|
||||
var connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||
connection.response.subscribe();
|
||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should use array buffer body without type with custom content type header to the request',
|
||||
() => {
|
||||
var headers = new Headers({'Content-Type': 'text/css'});
|
||||
var body = new ArrayBuffer(512);
|
||||
var longInt8View = new Uint8Array(body);
|
||||
for (var i = 0; i < longInt8View.length; i++) {
|
||||
longInt8View[i] = i % 255;
|
||||
}
|
||||
var base = new BaseRequestOptions();
|
||||
var connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||
new MockBrowserXHR());
|
||||
connection.response.subscribe();
|
||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/css');
|
||||
});
|
||||
() => {
|
||||
var headers = new Headers({'Content-Type': 'text/css'});
|
||||
var body = new ArrayBuffer(512);
|
||||
var longInt8View = new Uint8Array(body);
|
||||
for (var i = 0; i < longInt8View.length; i++) {
|
||||
longInt8View[i] = i % 255;
|
||||
}
|
||||
var base = new BaseRequestOptions();
|
||||
var connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||
new MockBrowserXHR());
|
||||
connection.response.subscribe();
|
||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/css');
|
||||
});
|
||||
}
|
||||
|
||||
it('should return the correct status code',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 418;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(
|
||||
(res: Response) => {
|
||||
@ -367,15 +360,16 @@ export function main() {
|
||||
var nextCalled = false;
|
||||
var errorCalled = false;
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(
|
||||
(res: Response) => {
|
||||
nextCalled = true;
|
||||
expect(res.status).toBe(statusCode);
|
||||
},
|
||||
errRes => { errorCalled = true; }, () => {
|
||||
errRes => { errorCalled = true; },
|
||||
() => {
|
||||
expect(nextCalled).toBe(true);
|
||||
expect(errorCalled).toBe(false);
|
||||
async.done();
|
||||
@ -385,47 +379,54 @@ export function main() {
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should set ok to true on 200 return', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
it('should set ok to true on 200 return',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(res => {
|
||||
expect(res.ok).toBe(true);
|
||||
async.done();
|
||||
});
|
||||
connection.response.subscribe(res => {
|
||||
expect(res.ok).toBe(true);
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should set ok to false on 300 return', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 300;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
it('should set ok to false on 300 return',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 300;
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(res => { throw 'should not be called'; }, errRes => {
|
||||
expect(errRes.ok).toBe(false);
|
||||
async.done();
|
||||
});
|
||||
connection.response.subscribe(
|
||||
res => { throw 'should not be called'; },
|
||||
errRes => {
|
||||
expect(errRes.ok).toBe(false);
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should call error and not complete on 300+ codes',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var nextCalled = false;
|
||||
var errorCalled = false;
|
||||
var statusCode = 301;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe((res: Response) => { nextCalled = true; }, errRes => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
expect(nextCalled).toBe(false);
|
||||
async.done();
|
||||
}, () => { throw 'should not be called'; });
|
||||
connection.response.subscribe(
|
||||
(res: Response) => { nextCalled = true; },
|
||||
errRes => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
expect(nextCalled).toBe(false);
|
||||
async.done();
|
||||
},
|
||||
() => { throw 'should not be called'; });
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
@ -434,8 +435,8 @@ export function main() {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 1223;
|
||||
var normalizedCode = 204;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.status).toBe(normalizedCode);
|
||||
@ -494,9 +495,9 @@ export function main() {
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should strip XSSI prefix from errors', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var conn =
|
||||
new XHRConnection(sampleRequest, new MockBrowserXHR(), new ResponseOptions());
|
||||
it('should strip XSSI prefix from errors',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var conn = new XHRConnection(sampleRequest, new MockBrowserXHR(), new ResponseOptions());
|
||||
conn.response.subscribe(null, (res: Response) => {
|
||||
expect(res.text()).toBe('{json: "object"}');
|
||||
async.done();
|
||||
@ -509,22 +510,21 @@ export function main() {
|
||||
it('should parse response headers and add them to the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
let responseHeaderString =
|
||||
`Date: Fri, 20 Nov 2015 01:45:26 GMT
|
||||
let responseHeaderString = `Date: Fri, 20 Nov 2015 01:45:26 GMT
|
||||
Content-Type: application/json; charset=utf-8
|
||||
Transfer-Encoding: chunked
|
||||
Connection: keep-alive`
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.headers.get('Date')).toEqual('Fri, 20 Nov 2015 01:45:26 GMT');
|
||||
expect(res.headers.get('Content-Type')).toEqual('application/json; charset=utf-8');
|
||||
expect(res.headers.get('Transfer-Encoding')).toEqual('chunked');
|
||||
expect(res.headers.get('Connection')).toEqual('keep-alive');
|
||||
async.done();
|
||||
});
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.headers.get('Date')).toEqual('Fri, 20 Nov 2015 01:45:26 GMT');
|
||||
expect(res.headers.get('Content-Type')).toEqual('application/json; charset=utf-8');
|
||||
expect(res.headers.get('Transfer-Encoding')).toEqual('chunked');
|
||||
expect(res.headers.get('Connection')).toEqual('keep-alive');
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setResponseHeaders(responseHeaderString);
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
@ -534,8 +534,8 @@ export function main() {
|
||||
it('should add the responseURL to the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.url).toEqual('http://google.com');
|
||||
@ -550,15 +550,15 @@ export function main() {
|
||||
it('should add use the X-Request-URL in CORS situations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({status: statusCode}));
|
||||
var connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
var responseHeaders = `X-Request-URL: http://somedomain.com
|
||||
Foo: Bar`
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.url).toEqual('http://somedomain.com');
|
||||
async.done();
|
||||
});
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.url).toEqual('http://somedomain.com');
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setResponseHeaders(responseHeaders);
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
@ -603,11 +603,11 @@ export function main() {
|
||||
var responseHeaders = `X-Request-URL: http://somedomain.com
|
||||
Foo: Bar`
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.url).toEqual('http://somedomain.com');
|
||||
expect(existingXHRs[0].withCredentials).toBeTruthy();
|
||||
async.done();
|
||||
});
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.url).toEqual('http://somedomain.com');
|
||||
expect(existingXHRs[0].withCredentials).toBeTruthy();
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setResponseHeaders(responseHeaders);
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
|
@ -1,13 +1,4 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {BaseRequestOptions, RequestOptions} from '../src/base_request_options';
|
||||
import {RequestMethod} from '../src/enums';
|
||||
|
||||
|
@ -1,16 +1,8 @@
|
||||
import {Headers} from '../src/headers';
|
||||
import {Json} from '../src/facade/lang';
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {Map, StringMapWrapper} from '../src/facade/collection';
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {Json} from '../src/facade/lang';
|
||||
import {Headers} from '../src/headers';
|
||||
|
||||
export function main() {
|
||||
describe('Headers', () => {
|
||||
|
@ -1,36 +1,12 @@
|
||||
import {
|
||||
afterEach,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {Injector, ReflectiveInjector, provide} from '@angular/core';
|
||||
import {afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {Injector, provide, ReflectiveInjector} from '@angular/core';
|
||||
import {MockBackend, MockConnection} from '../testing/mock_backend';
|
||||
import {
|
||||
BaseRequestOptions,
|
||||
ConnectionBackend,
|
||||
Request,
|
||||
RequestMethod,
|
||||
RequestOptions,
|
||||
Response,
|
||||
ResponseOptions,
|
||||
URLSearchParams,
|
||||
JSONP_PROVIDERS,
|
||||
HTTP_PROVIDERS,
|
||||
XHRBackend,
|
||||
JSONPBackend,
|
||||
Http,
|
||||
Jsonp
|
||||
} from '../http';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Subject} from 'rxjs/Subject';
|
||||
|
||||
import {BaseRequestOptions, ConnectionBackend, HTTP_PROVIDERS, Http, JSONPBackend, JSONP_PROVIDERS, Jsonp, Request, RequestMethod, RequestOptions, Response, ResponseOptions, URLSearchParams, XHRBackend} from '../http';
|
||||
import {MockBackend, MockConnection} from '../testing/mock_backend';
|
||||
|
||||
export function main() {
|
||||
describe('injectables', () => {
|
||||
var url = 'http://foo.bar';
|
||||
@ -49,9 +25,7 @@ export function main() {
|
||||
]);
|
||||
|
||||
childInjector = parentInjector.resolveAndCreateChild([
|
||||
HTTP_PROVIDERS,
|
||||
JSONP_PROVIDERS,
|
||||
{provide: XHRBackend, useClass: MockBackend},
|
||||
HTTP_PROVIDERS, JSONP_PROVIDERS, {provide: XHRBackend, useClass: MockBackend},
|
||||
{provide: JSONPBackend, useClass: MockBackend}
|
||||
]);
|
||||
|
||||
@ -95,9 +69,7 @@ export function main() {
|
||||
var jsonp: Jsonp;
|
||||
beforeEach(() => {
|
||||
injector = ReflectiveInjector.resolveAndCreate([
|
||||
BaseRequestOptions,
|
||||
MockBackend,
|
||||
{
|
||||
BaseRequestOptions, MockBackend, {
|
||||
provide: Http,
|
||||
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
|
||||
return new Http(backend, defaultOptions);
|
||||
@ -154,11 +126,10 @@ export function main() {
|
||||
it('should perform a get request for given url if only passed a string',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
http.request('http://basic.connection').subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a post request for given url if options include a method',
|
||||
@ -168,11 +139,10 @@ export function main() {
|
||||
c.mockRespond(baseResponse);
|
||||
});
|
||||
let requestOptions = new RequestOptions({method: RequestMethod.Post});
|
||||
http.request('http://basic.connection', requestOptions)
|
||||
.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
http.request('http://basic.connection', requestOptions).subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a post request for given url if options include a method',
|
||||
@ -182,30 +152,32 @@ export function main() {
|
||||
c.mockRespond(baseResponse);
|
||||
});
|
||||
let requestOptions = {method: RequestMethod.Post};
|
||||
http.request('http://basic.connection', requestOptions)
|
||||
.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
http.request('http://basic.connection', requestOptions).subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should perform a get request and complete the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
.subscribe(
|
||||
(res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
}));
|
||||
|
||||
it('should perform multiple get requests and complete the responses',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
||||
|
||||
http.request('http://basic.connection').subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('base response');
|
||||
});
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => { expect(res.text()).toBe('base response'); });
|
||||
http.request('http://basic.connection')
|
||||
.subscribe((res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
.subscribe(
|
||||
(res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||
() => { async.done(); });
|
||||
}));
|
||||
|
||||
it('should throw if url is not a string or Request', () => {
|
||||
@ -371,9 +343,8 @@ export function main() {
|
||||
it('should allow case insensitive strings for method names', () => {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
backend.connections.subscribe((c: MockConnection) => {
|
||||
expect(c.request.method)
|
||||
.toBe(RequestMethod.Post)
|
||||
c.mockRespond(new Response(new ResponseOptions({body: 'Thank you'})));
|
||||
expect(c.request.method).toBe(RequestMethod.Post)
|
||||
c.mockRespond(new Response(new ResponseOptions({body: 'Thank you'})));
|
||||
async.done();
|
||||
});
|
||||
http.request(
|
||||
|
@ -1,8 +1,4 @@
|
||||
import {
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {describe, expect, it,} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {ResponseOptions} from '../src/base_response_options';
|
||||
import {Response} from '../src/static_response';
|
||||
|
@ -1,37 +1,28 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {URLSearchParams} from '../src/url_search_params';
|
||||
|
||||
export function main() {
|
||||
describe('URLSearchParams', () => {
|
||||
it('should conform to spec', () => {
|
||||
var paramsString = "q=URLUtils.searchParams&topic=api";
|
||||
var paramsString = 'q=URLUtils.searchParams&topic=api';
|
||||
var searchParams = new URLSearchParams(paramsString);
|
||||
|
||||
// Tests borrowed from example at
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
|
||||
// Compliant with spec described at https://url.spec.whatwg.org/#urlsearchparams
|
||||
expect(searchParams.has("topic")).toBe(true);
|
||||
expect(searchParams.has("foo")).toBe(false);
|
||||
expect(searchParams.get("topic")).toEqual("api");
|
||||
expect(searchParams.getAll("topic")).toEqual(["api"]);
|
||||
expect(searchParams.get("foo")).toBe(null);
|
||||
searchParams.append("topic", "webdev");
|
||||
expect(searchParams.getAll("topic")).toEqual(["api", "webdev"]);
|
||||
expect(searchParams.toString()).toEqual("q=URLUtils.searchParams&topic=api&topic=webdev");
|
||||
searchParams.delete("topic");
|
||||
expect(searchParams.toString()).toEqual("q=URLUtils.searchParams");
|
||||
expect(searchParams.has('topic')).toBe(true);
|
||||
expect(searchParams.has('foo')).toBe(false);
|
||||
expect(searchParams.get('topic')).toEqual('api');
|
||||
expect(searchParams.getAll('topic')).toEqual(['api']);
|
||||
expect(searchParams.get('foo')).toBe(null);
|
||||
searchParams.append('topic', 'webdev');
|
||||
expect(searchParams.getAll('topic')).toEqual(['api', 'webdev']);
|
||||
expect(searchParams.toString()).toEqual('q=URLUtils.searchParams&topic=api&topic=webdev');
|
||||
searchParams.delete('topic');
|
||||
expect(searchParams.toString()).toEqual('q=URLUtils.searchParams');
|
||||
|
||||
// Test default constructor
|
||||
expect(new URLSearchParams().toString()).toBe("");
|
||||
expect(new URLSearchParams().toString()).toBe('');
|
||||
});
|
||||
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ReplaySubject} from 'rxjs/ReplaySubject';
|
||||
import {Subject} from 'rxjs/Subject';
|
||||
import {take} from 'rxjs/operator/take';
|
||||
|
||||
import {ReadyState} from '../src/enums';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {isPresent} from '../src/facade/lang';
|
||||
import {Connection, ConnectionBackend} from '../src/interfaces';
|
||||
import {Request} from '../src/static_request';
|
||||
import {Response} from '../src/static_response';
|
||||
import {ReadyState} from '../src/enums';
|
||||
import {Connection, ConnectionBackend} from '../src/interfaces';
|
||||
import {isPresent} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {Subject} from 'rxjs/Subject';
|
||||
import {ReplaySubject} from 'rxjs/ReplaySubject';
|
||||
import {take} from 'rxjs/operator/take';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@ -50,7 +52,8 @@ export class MockConnection implements Connection {
|
||||
* var connection;
|
||||
* backend.connections.subscribe(c => connection = c);
|
||||
* http.request('data.json').subscribe(res => console.log(res.text()));
|
||||
* connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs 'fake response'
|
||||
* connection.mockRespond(new Response(new ResponseOptions({ body: 'fake response' }))); //logs
|
||||
* 'fake response'
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
@ -187,8 +190,8 @@ export class MockBackend implements ConnectionBackend {
|
||||
constructor() {
|
||||
this.connectionsArray = [];
|
||||
this.connections = new Subject();
|
||||
this.connections.subscribe((connection: MockConnection) =>
|
||||
this.connectionsArray.push(connection));
|
||||
this.connections.subscribe(
|
||||
(connection: MockConnection) => this.connectionsArray.push(connection));
|
||||
this.pendingConnections = new Subject();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user