Revert "fix(http): Update types for TypeScript nullability support"
This reverts commit c36ec9bf60
.
Broke in G3.
This commit is contained in:
parent
ea8ffc9841
commit
268884296a
|
@ -10,7 +10,7 @@ import {Injectable} from '@angular/core';
|
||||||
|
|
||||||
let _nextRequestId = 0;
|
let _nextRequestId = 0;
|
||||||
export const JSONP_HOME = '__ng_jsonp__';
|
export const JSONP_HOME = '__ng_jsonp__';
|
||||||
let _jsonpConnections: {[key: string]: any}|null = null;
|
let _jsonpConnections: {[key: string]: any} = null;
|
||||||
|
|
||||||
function _getJsonpConnections(): {[key: string]: any} {
|
function _getJsonpConnections(): {[key: string]: any} {
|
||||||
const w: {[key: string]: any} = typeof window == 'object' ? window : {};
|
const w: {[key: string]: any} = typeof window == 'object' ? window : {};
|
||||||
|
|
|
@ -115,7 +115,7 @@ export class XHRConnection implements Connection {
|
||||||
if (!req.headers.has('Accept')) {
|
if (!req.headers.has('Accept')) {
|
||||||
req.headers.append('Accept', 'application/json, text/plain, */*');
|
req.headers.append('Accept', 'application/json, text/plain, */*');
|
||||||
}
|
}
|
||||||
req.headers.forEach((values, name) => _xhr.setRequestHeader(name !, values.join(',')));
|
req.headers.forEach((values, name) => _xhr.setRequestHeader(name, values.join(',')));
|
||||||
|
|
||||||
// Select the correct buffer type to store the response
|
// Select the correct buffer type to store the response
|
||||||
if (req.responseType != null && _xhr.responseType != null) {
|
if (req.responseType != null && _xhr.responseType != null) {
|
||||||
|
|
|
@ -44,11 +44,11 @@ export class RequestOptions {
|
||||||
* Http method with which to execute a {@link Request}.
|
* Http method with which to execute a {@link Request}.
|
||||||
* Acceptable methods are defined in the {@link RequestMethod} enum.
|
* Acceptable methods are defined in the {@link RequestMethod} enum.
|
||||||
*/
|
*/
|
||||||
method: RequestMethod|string|null;
|
method: RequestMethod|string;
|
||||||
/**
|
/**
|
||||||
* {@link Headers} to be attached to a {@link Request}.
|
* {@link Headers} to be attached to a {@link Request}.
|
||||||
*/
|
*/
|
||||||
headers: Headers|null;
|
headers: Headers;
|
||||||
/**
|
/**
|
||||||
* Body to be used when creating a {@link Request}.
|
* Body to be used when creating a {@link Request}.
|
||||||
*/
|
*/
|
||||||
|
@ -56,7 +56,7 @@ export class RequestOptions {
|
||||||
/**
|
/**
|
||||||
* Url with which to perform a {@link Request}.
|
* Url with which to perform a {@link Request}.
|
||||||
*/
|
*/
|
||||||
url: string|null;
|
url: string;
|
||||||
/**
|
/**
|
||||||
* Search parameters to be included in a {@link Request}.
|
* Search parameters to be included in a {@link Request}.
|
||||||
*/
|
*/
|
||||||
|
@ -72,11 +72,11 @@ export class RequestOptions {
|
||||||
/**
|
/**
|
||||||
* Enable use credentials for a {@link Request}.
|
* Enable use credentials for a {@link Request}.
|
||||||
*/
|
*/
|
||||||
withCredentials: boolean|null;
|
withCredentials: boolean;
|
||||||
/*
|
/*
|
||||||
* Select a buffer to store the response, such as ArrayBuffer, Blob, Json (or Document)
|
* Select a buffer to store the response, such as ArrayBuffer, Blob, Json (or Document)
|
||||||
*/
|
*/
|
||||||
responseType: ResponseContentType|null;
|
responseType: ResponseContentType;
|
||||||
|
|
||||||
// TODO(Dzmitry): remove search when this.search is removed
|
// TODO(Dzmitry): remove search when this.search is removed
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -128,8 +128,8 @@ export class RequestOptions {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _mergeSearchParams(params?: string|URLSearchParams|{[key: string]: any | any[]}|
|
private _mergeSearchParams(params: string|URLSearchParams|
|
||||||
null): URLSearchParams {
|
{[key: string]: any | any[]}): URLSearchParams {
|
||||||
if (!params) return this.params;
|
if (!params) return this.params;
|
||||||
|
|
||||||
if (params instanceof URLSearchParams) {
|
if (params instanceof URLSearchParams) {
|
||||||
|
|
|
@ -46,25 +46,25 @@ export class ResponseOptions {
|
||||||
/**
|
/**
|
||||||
* String, Object, ArrayBuffer or Blob representing the body of the {@link Response}.
|
* String, Object, ArrayBuffer or Blob representing the body of the {@link Response}.
|
||||||
*/
|
*/
|
||||||
body: string|Object|ArrayBuffer|Blob|null;
|
body: string|Object|ArrayBuffer|Blob;
|
||||||
/**
|
/**
|
||||||
* Http {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html status code}
|
* Http {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html status code}
|
||||||
* associated with the response.
|
* associated with the response.
|
||||||
*/
|
*/
|
||||||
status: number|null;
|
status: number;
|
||||||
/**
|
/**
|
||||||
* Response {@link Headers headers}
|
* Response {@link Headers headers}
|
||||||
*/
|
*/
|
||||||
headers: Headers|null;
|
headers: Headers;
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
statusText: string|null;
|
statusText: string;
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
type: ResponseType|null;
|
type: ResponseType;
|
||||||
url: string|null;
|
url: string;
|
||||||
constructor({body, status, headers, statusText, type, url}: ResponseOptionsArgs = {}) {
|
constructor({body, status, headers, statusText, type, url}: ResponseOptionsArgs = {}) {
|
||||||
this.body = body != null ? body : null;
|
this.body = body != null ? body : null;
|
||||||
this.status = status != null ? status : null;
|
this.status = status != null ? status : null;
|
||||||
|
|
|
@ -41,7 +41,7 @@ export class Headers {
|
||||||
_normalizedNames: Map<string, string> = new Map();
|
_normalizedNames: Map<string, string> = new Map();
|
||||||
|
|
||||||
// TODO(vicb): any -> string|string[]
|
// TODO(vicb): any -> string|string[]
|
||||||
constructor(headers?: Headers|{[name: string]: any}|null) {
|
constructor(headers?: Headers|{[name: string]: any}) {
|
||||||
if (!headers) {
|
if (!headers) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,7 @@ export class Headers {
|
||||||
this._headers.delete(lcName);
|
this._headers.delete(lcName);
|
||||||
}
|
}
|
||||||
|
|
||||||
forEach(fn: (values: string[], name: string|undefined, headers: Map<string, string[]>) => void):
|
forEach(fn: (values: string[], name: string, headers: Map<string, string[]>) => void): void {
|
||||||
void {
|
|
||||||
this._headers.forEach(
|
this._headers.forEach(
|
||||||
(values, lcName) => fn(values, this._normalizedNames.get(lcName), this._headers));
|
(values, lcName) => fn(values, this._normalizedNames.get(lcName), this._headers));
|
||||||
}
|
}
|
||||||
|
@ -109,7 +108,7 @@ export class Headers {
|
||||||
/**
|
/**
|
||||||
* Returns first header that matches given name.
|
* Returns first header that matches given name.
|
||||||
*/
|
*/
|
||||||
get(name: string): string|null {
|
get(name: string): string {
|
||||||
const values = this.getAll(name);
|
const values = this.getAll(name);
|
||||||
|
|
||||||
if (values === null) {
|
if (values === null) {
|
||||||
|
@ -158,7 +157,7 @@ export class Headers {
|
||||||
this._headers.forEach((values: string[], name: string) => {
|
this._headers.forEach((values: string[], name: string) => {
|
||||||
const split: string[] = [];
|
const split: string[] = [];
|
||||||
values.forEach(v => split.push(...v.split(',')));
|
values.forEach(v => split.push(...v.split(',')));
|
||||||
serialized[this._normalizedNames.get(name) !] = split;
|
serialized[this._normalizedNames.get(name)] = split;
|
||||||
});
|
});
|
||||||
|
|
||||||
return serialized;
|
return serialized;
|
||||||
|
@ -167,8 +166,8 @@ export class Headers {
|
||||||
/**
|
/**
|
||||||
* Returns list of header values for a given name.
|
* Returns list of header values for a given name.
|
||||||
*/
|
*/
|
||||||
getAll(name: string): string[]|null {
|
getAll(name: string): string[] {
|
||||||
return this.has(name) ? this._headers.get(name.toLowerCase()) || null : null;
|
return this.has(name) ? this._headers.get(name.toLowerCase()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,10 +8,9 @@
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
|
|
||||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||||
import {RequestMethod} from './enums';
|
import {RequestMethod} from './enums';
|
||||||
import {ConnectionBackend, RequestArgs, RequestOptionsArgs} from './interfaces';
|
import {ConnectionBackend, RequestOptionsArgs} from './interfaces';
|
||||||
import {Request} from './static_request';
|
import {Request} from './static_request';
|
||||||
import {Response} from './static_response';
|
import {Response} from './static_response';
|
||||||
|
|
||||||
|
@ -20,8 +19,8 @@ function httpRequest(backend: ConnectionBackend, request: Request): Observable<R
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeOptions(
|
function mergeOptions(
|
||||||
defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs | undefined,
|
defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs, method: RequestMethod,
|
||||||
method: RequestMethod, url: string): RequestArgs {
|
url: string): RequestOptions {
|
||||||
const newOptions = defaultOpts;
|
const newOptions = defaultOpts;
|
||||||
if (providedOpts) {
|
if (providedOpts) {
|
||||||
// Hack so Dart can used named parameters
|
// Hack so Dart can used named parameters
|
||||||
|
@ -34,10 +33,10 @@ function mergeOptions(
|
||||||
body: providedOpts.body,
|
body: providedOpts.body,
|
||||||
withCredentials: providedOpts.withCredentials,
|
withCredentials: providedOpts.withCredentials,
|
||||||
responseType: providedOpts.responseType
|
responseType: providedOpts.responseType
|
||||||
})) as RequestArgs;
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return newOptions.merge(new RequestOptions({method, url})) as RequestArgs;
|
return newOptions.merge(new RequestOptions({method, url}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,14 +32,14 @@ export function normalizeMethodName(method: string | RequestMethod): RequestMeth
|
||||||
|
|
||||||
export const isSuccess = (status: number): boolean => (status >= 200 && status < 300);
|
export const isSuccess = (status: number): boolean => (status >= 200 && status < 300);
|
||||||
|
|
||||||
export function getResponseURL(xhr: any): string|null {
|
export function getResponseURL(xhr: any): string {
|
||||||
if ('responseURL' in xhr) {
|
if ('responseURL' in xhr) {
|
||||||
return xhr.responseURL;
|
return xhr.responseURL;
|
||||||
}
|
}
|
||||||
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
|
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
|
||||||
return xhr.getResponseHeader('X-Request-URL');
|
return xhr.getResponseHeader('X-Request-URL');
|
||||||
}
|
}
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stringToArrayBuffer(input: String): ArrayBuffer {
|
export function stringToArrayBuffer(input: String): ArrayBuffer {
|
||||||
|
|
|
@ -46,21 +46,21 @@ export abstract class XSRFStrategy { abstract configureRequest(req: Request): vo
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export interface RequestOptionsArgs {
|
export interface RequestOptionsArgs {
|
||||||
url?: string|null;
|
url?: string;
|
||||||
method?: string|RequestMethod|null;
|
method?: string|RequestMethod;
|
||||||
/** @deprecated from 4.0.0. Use params instead. */
|
/** @deprecated from 4.0.0. Use params instead. */
|
||||||
search?: string|URLSearchParams|{[key: string]: any | any[]}|null;
|
search?: string|URLSearchParams|{[key: string]: any | any[]};
|
||||||
params?: string|URLSearchParams|{[key: string]: any | any[]}|null;
|
params?: string|URLSearchParams|{[key: string]: any | any[]};
|
||||||
headers?: Headers|null;
|
headers?: Headers;
|
||||||
body?: any;
|
body?: any;
|
||||||
withCredentials?: boolean|null;
|
withCredentials?: boolean;
|
||||||
responseType?: ResponseContentType|null;
|
responseType?: ResponseContentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required structure when constructing new Request();
|
* Required structure when constructing new Request();
|
||||||
*/
|
*/
|
||||||
export interface RequestArgs extends RequestOptionsArgs { url: string|null; }
|
export interface RequestArgs extends RequestOptionsArgs { url: string; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for options to construct a Response, based on
|
* Interface for options to construct a Response, based on
|
||||||
|
@ -69,10 +69,10 @@ export interface RequestArgs extends RequestOptionsArgs { url: string|null; }
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export interface ResponseOptionsArgs {
|
export interface ResponseOptionsArgs {
|
||||||
body?: string|Object|FormData|ArrayBuffer|Blob|null;
|
body?: string|Object|FormData|ArrayBuffer|Blob;
|
||||||
status?: number|null;
|
status?: number;
|
||||||
statusText?: string|null;
|
statusText?: string;
|
||||||
headers?: Headers|null;
|
headers?: Headers;
|
||||||
type?: ResponseType|null;
|
type?: ResponseType;
|
||||||
url?: string|null;
|
url?: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ export class Request extends Body {
|
||||||
super();
|
super();
|
||||||
// TODO: assert that url is present
|
// TODO: assert that url is present
|
||||||
const url = requestOptions.url;
|
const url = requestOptions.url;
|
||||||
this.url = requestOptions.url !;
|
this.url = requestOptions.url;
|
||||||
if (requestOptions.params) {
|
if (requestOptions.params) {
|
||||||
const params = requestOptions.params.toString();
|
const params = requestOptions.params.toString();
|
||||||
if (params.length > 0) {
|
if (params.length > 0) {
|
||||||
|
@ -88,13 +88,13 @@ export class Request extends Body {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._body = requestOptions.body;
|
this._body = requestOptions.body;
|
||||||
this.method = normalizeMethodName(requestOptions.method !);
|
this.method = normalizeMethodName(requestOptions.method);
|
||||||
// TODO(jeffbcross): implement behavior
|
// TODO(jeffbcross): implement behavior
|
||||||
// Defaults to 'omit', consistent with browser
|
// Defaults to 'omit', consistent with browser
|
||||||
this.headers = new Headers(requestOptions.headers);
|
this.headers = new Headers(requestOptions.headers);
|
||||||
this.contentType = this.detectContentType();
|
this.contentType = this.detectContentType();
|
||||||
this.withCredentials = requestOptions.withCredentials !;
|
this.withCredentials = requestOptions.withCredentials;
|
||||||
this.responseType = requestOptions.responseType !;
|
this.responseType = requestOptions.responseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,7 +63,7 @@ export class Response extends Body {
|
||||||
*
|
*
|
||||||
* Defaults to "OK"
|
* Defaults to "OK"
|
||||||
*/
|
*/
|
||||||
statusText: string|null;
|
statusText: string;
|
||||||
/**
|
/**
|
||||||
* Non-standard property
|
* Non-standard property
|
||||||
*
|
*
|
||||||
|
@ -81,17 +81,17 @@ export class Response extends Body {
|
||||||
* Headers object based on the `Headers` class in the [Fetch
|
* Headers object based on the `Headers` class in the [Fetch
|
||||||
* Spec](https://fetch.spec.whatwg.org/#headers-class).
|
* Spec](https://fetch.spec.whatwg.org/#headers-class).
|
||||||
*/
|
*/
|
||||||
headers: Headers|null;
|
headers: Headers;
|
||||||
|
|
||||||
constructor(responseOptions: ResponseOptions) {
|
constructor(responseOptions: ResponseOptions) {
|
||||||
super();
|
super();
|
||||||
this._body = responseOptions.body;
|
this._body = responseOptions.body;
|
||||||
this.status = responseOptions.status !;
|
this.status = responseOptions.status;
|
||||||
this.ok = (this.status >= 200 && this.status <= 299);
|
this.ok = (this.status >= 200 && this.status <= 299);
|
||||||
this.statusText = responseOptions.statusText;
|
this.statusText = responseOptions.statusText;
|
||||||
this.headers = responseOptions.headers;
|
this.headers = responseOptions.headers;
|
||||||
this.type = responseOptions.type !;
|
this.type = responseOptions.type;
|
||||||
this.url = responseOptions.url !;
|
this.url = responseOptions.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
|
|
|
@ -93,7 +93,7 @@ export class URLSearchParams {
|
||||||
|
|
||||||
has(param: string): boolean { return this.paramsMap.has(param); }
|
has(param: string): boolean { return this.paramsMap.has(param); }
|
||||||
|
|
||||||
get(param: string): string|null {
|
get(param: string): string {
|
||||||
const storedParam = this.paramsMap.get(param);
|
const storedParam = this.paramsMap.get(param);
|
||||||
|
|
||||||
return Array.isArray(storedParam) ? storedParam[0] : null;
|
return Array.isArray(storedParam) ? storedParam[0] : null;
|
||||||
|
|
|
@ -59,14 +59,13 @@ export function main() {
|
||||||
]);
|
]);
|
||||||
backend = injector.get(JSONPBackend);
|
backend = injector.get(JSONPBackend);
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
sampleRequest =
|
sampleRequest = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
|
||||||
new Request(base.merge(new RequestOptions({url: 'https://google.com'})) as any);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => { existingScripts = []; });
|
afterEach(() => { existingScripts = []; });
|
||||||
|
|
||||||
it('should create a connection', () => {
|
it('should create a connection', () => {
|
||||||
let instance: JSONPConnection = undefined !;
|
let instance: JSONPConnection;
|
||||||
expect(() => instance = backend.createConnection(sampleRequest)).not.toThrow();
|
expect(() => instance = backend.createConnection(sampleRequest)).not.toThrow();
|
||||||
expect(instance).toBeAnInstanceOf(JSONPConnection);
|
expect(instance).toBeAnInstanceOf(JSONPConnection);
|
||||||
});
|
});
|
||||||
|
@ -147,8 +146,8 @@ export function main() {
|
||||||
RequestMethod.Head, RequestMethod.Patch]
|
RequestMethod.Head, RequestMethod.Patch]
|
||||||
.forEach(method => {
|
.forEach(method => {
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const req = new Request(base.merge(
|
const req = new Request(
|
||||||
new RequestOptions({url: 'https://google.com', method: method})) as any);
|
base.merge(new RequestOptions({url: 'https://google.com', method: method})));
|
||||||
expect(() => new JSONPConnection_(req, new MockBrowserJsonp()).response.subscribe())
|
expect(() => new JSONPConnection_(req, new MockBrowserJsonp()).response.subscribe())
|
||||||
.toThrowError();
|
.toThrowError();
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,11 +31,9 @@ export function main() {
|
||||||
[{provide: ResponseOptions, useClass: BaseResponseOptions}, MockBackend]);
|
[{provide: ResponseOptions, useClass: BaseResponseOptions}, MockBackend]);
|
||||||
backend = injector.get(MockBackend);
|
backend = injector.get(MockBackend);
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
sampleRequest1 =
|
sampleRequest1 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
|
||||||
new Request(base.merge(new RequestOptions({url: 'https://google.com'})) as any);
|
|
||||||
sampleResponse1 = new Response(new ResponseOptions({body: 'response1'}));
|
sampleResponse1 = new Response(new ResponseOptions({body: 'response1'}));
|
||||||
sampleRequest2 =
|
sampleRequest2 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
|
||||||
new Request(base.merge(new RequestOptions({url: 'https://google.com'})) as any);
|
|
||||||
sampleResponse2 = new Response(new ResponseOptions({body: 'response2'}));
|
sampleResponse2 = new Response(new ResponseOptions({body: 'response2'}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -67,7 +65,7 @@ export function main() {
|
||||||
it('should allow responding after subscription with an error',
|
it('should allow responding after subscription with an error',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const connection: MockConnection = backend.createConnection(sampleRequest1);
|
const connection: MockConnection = backend.createConnection(sampleRequest1);
|
||||||
connection.response.subscribe(null !, () => { async.done(); });
|
connection.response.subscribe(null, () => { async.done(); });
|
||||||
connection.mockError(new Error('nope'));
|
connection.mockError(new Error('nope'));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -100,12 +98,12 @@ export function main() {
|
||||||
xit('should allow double subscribing',
|
xit('should allow double subscribing',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const responses: Response[] = [sampleResponse1, sampleResponse2];
|
const responses: Response[] = [sampleResponse1, sampleResponse2];
|
||||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(responses.shift() !));
|
backend.connections.subscribe((c: MockConnection) => c.mockRespond(responses.shift()));
|
||||||
const responseObservable: ReplaySubject<Response> =
|
const responseObservable: ReplaySubject<Response> =
|
||||||
backend.createConnection(sampleRequest1).response;
|
backend.createConnection(sampleRequest1).response;
|
||||||
responseObservable.subscribe(res => expect(res.text()).toBe('response1'));
|
responseObservable.subscribe(res => expect(res.text()).toBe('response1'));
|
||||||
responseObservable.subscribe(
|
responseObservable.subscribe(
|
||||||
res => expect(res.text()).toBe('response2'), null !, async.done);
|
res => expect(res.text()).toBe('response2'), null, async.done);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// TODO(robwormald): readyStates are leaving?
|
// TODO(robwormald): readyStates are leaving?
|
||||||
|
|
|
@ -75,7 +75,7 @@ class MockBrowserXHR extends BrowserXhr {
|
||||||
|
|
||||||
removeEventListener(type: string, cb: Function) { this.callbacks.delete(type); }
|
removeEventListener(type: string, cb: Function) { this.callbacks.delete(type); }
|
||||||
|
|
||||||
dispatchEvent(type: string) { this.callbacks.get(type) !({}); }
|
dispatchEvent(type: string) { this.callbacks.get(type)({}); }
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
const xhr = new MockBrowserXHR();
|
const xhr = new MockBrowserXHR();
|
||||||
|
@ -99,8 +99,7 @@ export function main() {
|
||||||
beforeEach(inject([XHRBackend], (be: XHRBackend) => {
|
beforeEach(inject([XHRBackend], (be: XHRBackend) => {
|
||||||
backend = be;
|
backend = be;
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
sampleRequest =
|
sampleRequest = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));
|
||||||
new Request(base.merge(new RequestOptions({url: 'https://google.com'})) as any);
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
afterEach(() => { existingXHRs = []; });
|
afterEach(() => { existingXHRs = []; });
|
||||||
|
@ -164,7 +163,7 @@ export function main() {
|
||||||
sampleRequest, new MockBrowserXHR(),
|
sampleRequest, new MockBrowserXHR(),
|
||||||
new ResponseOptions({type: ResponseType.Error}));
|
new ResponseOptions({type: ResponseType.Error}));
|
||||||
connection.response.subscribe(
|
connection.response.subscribe(
|
||||||
(res: Response) => { expect(res.type).toBe(ResponseType.Error); }, null !,
|
(res: Response) => { expect(res.type).toBe(ResponseType.Error); }, null,
|
||||||
() => { async.done(); });
|
() => { async.done(); });
|
||||||
existingXHRs[0].setStatusCode(200);
|
existingXHRs[0].setStatusCode(200);
|
||||||
existingXHRs[0].dispatchEvent('load');
|
existingXHRs[0].dispatchEvent('load');
|
||||||
|
@ -182,7 +181,7 @@ export function main() {
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
sampleRequest, new MockBrowserXHR(),
|
sampleRequest, new MockBrowserXHR(),
|
||||||
new ResponseOptions({type: ResponseType.Error}));
|
new ResponseOptions({type: ResponseType.Error}));
|
||||||
connection.response.subscribe(null !, (res: Response) => {
|
connection.response.subscribe(null, (res: Response) => {
|
||||||
expect(res.type).toBe(ResponseType.Error);
|
expect(res.type).toBe(ResponseType.Error);
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
|
@ -194,7 +193,7 @@ export function main() {
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
sampleRequest, new MockBrowserXHR(),
|
sampleRequest, new MockBrowserXHR(),
|
||||||
new ResponseOptions({type: ResponseType.Error}));
|
new ResponseOptions({type: ResponseType.Error}));
|
||||||
connection.response.subscribe(null !, (res: Response) => {
|
connection.response.subscribe(null, (res: Response) => {
|
||||||
expect(res.type).toBe(ResponseType.Error);
|
expect(res.type).toBe(ResponseType.Error);
|
||||||
expect(res.status).toEqual(0);
|
expect(res.status).toEqual(0);
|
||||||
expect(res.statusText).toEqual('');
|
expect(res.statusText).toEqual('');
|
||||||
|
@ -218,7 +217,7 @@ export function main() {
|
||||||
const body = 'Some body to love';
|
const body = 'Some body to love';
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body})) as any), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
expect(sendSpy).not.toHaveBeenCalled();
|
expect(sendSpy).not.toHaveBeenCalled();
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||||
|
@ -230,8 +229,7 @@ export function main() {
|
||||||
|
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({headers: headers})) as any),
|
new Request(base.merge(new RequestOptions({headers: headers}))), new MockBrowserXHR());
|
||||||
new MockBrowserXHR());
|
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/xml');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/xml');
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Breaking-Bad', '<3');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Breaking-Bad', '<3');
|
||||||
|
@ -242,7 +240,7 @@ export function main() {
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({headers})) as any), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({headers}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(setRequestHeaderSpy)
|
expect(setRequestHeaderSpy)
|
||||||
.toHaveBeenCalledWith('Accept', 'application/json, text/plain, */*');
|
.toHaveBeenCalledWith('Accept', 'application/json, text/plain, */*');
|
||||||
|
@ -252,7 +250,7 @@ export function main() {
|
||||||
const headers = new Headers({'Accept': 'text/xml'});
|
const headers = new Headers({'Accept': 'text/xml'});
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({headers})) as any), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({headers}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Accept', 'text/xml');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Accept', 'text/xml');
|
||||||
});
|
});
|
||||||
|
@ -262,7 +260,7 @@ export function main() {
|
||||||
const body = {test: 'val'};
|
const body = {test: 'val'};
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body, headers: headers})) as any),
|
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||||
new MockBrowserXHR());
|
new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/plain');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/plain');
|
||||||
|
@ -274,7 +272,7 @@ export function main() {
|
||||||
const body = {test: 'val'};
|
const body = {test: 'val'};
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body})) as any), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(JSON.stringify(body, null, 2));
|
expect(sendSpy).toHaveBeenCalledWith(JSON.stringify(body, null, 2));
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'application/json');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'application/json');
|
||||||
|
@ -284,7 +282,7 @@ export function main() {
|
||||||
const body = 23;
|
const body = 23;
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body})) as any), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith('23');
|
expect(sendSpy).toHaveBeenCalledWith('23');
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/plain');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/plain');
|
||||||
|
@ -294,7 +292,7 @@ export function main() {
|
||||||
const body = 'some string';
|
const body = 'some string';
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body})) as any), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/plain');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/plain');
|
||||||
|
@ -306,7 +304,7 @@ export function main() {
|
||||||
body.set('test2', 'val2');
|
body.set('test2', 'val2');
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body})) as any), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith('test1=val1&test2=val2');
|
expect(sendSpy).toHaveBeenCalledWith('test1=val1&test2=val2');
|
||||||
expect(setRequestHeaderSpy)
|
expect(setRequestHeaderSpy)
|
||||||
|
@ -339,8 +337,7 @@ export function main() {
|
||||||
body.append('userfile', blob);
|
body.append('userfile', blob);
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body})) as any),
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
new MockBrowserXHR());
|
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||||
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith();
|
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith();
|
||||||
|
@ -350,15 +347,14 @@ export function main() {
|
||||||
const body = createBlob(['body { color: red; }'], 'text/css');
|
const body = createBlob(['body { color: red; }'], 'text/css');
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body})) as any),
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
new MockBrowserXHR());
|
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/css');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/css');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use blob body without type to the request', () => {
|
it('should use blob body without type to the request', () => {
|
||||||
const body = createBlob(['body { color: red; }'], null !);
|
const body = createBlob(['body { color: red; }'], null);
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
|
@ -370,7 +366,7 @@ export function main() {
|
||||||
it('should use blob body without type with custom content type header to the request',
|
it('should use blob body without type with custom content type header to the request',
|
||||||
() => {
|
() => {
|
||||||
const headers = new Headers({'Content-Type': 'text/css'});
|
const headers = new Headers({'Content-Type': 'text/css'});
|
||||||
const body = createBlob(['body { color: red; }'], null !);
|
const body = createBlob(['body { color: red; }'], null);
|
||||||
const base = new BaseRequestOptions();
|
const base = new BaseRequestOptions();
|
||||||
const connection = new XHRConnection(
|
const connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||||
|
@ -594,7 +590,7 @@ export function main() {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||||
const conn =
|
const conn =
|
||||||
new XHRConnection(sampleRequest, new MockBrowserXHR(), new ResponseOptions());
|
new XHRConnection(sampleRequest, new MockBrowserXHR(), new ResponseOptions());
|
||||||
conn.response.subscribe(null !, (res: Response) => {
|
conn.response.subscribe(null, (res: Response) => {
|
||||||
expect(res.text()).toBe('{json: "object"}');
|
expect(res.text()).toBe('{json: "object"}');
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
|
@ -615,10 +611,10 @@ Transfer-Encoding: chunked
|
||||||
Connection: keep-alive`;
|
Connection: keep-alive`;
|
||||||
|
|
||||||
connection.response.subscribe((res: Response) => {
|
connection.response.subscribe((res: Response) => {
|
||||||
expect(res.headers !.get('Date')).toEqual('Fri, 20 Nov 2015 01:45:26 GMT');
|
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('Content-Type')).toEqual('application/json; charset=utf-8');
|
||||||
expect(res.headers !.get('Transfer-Encoding')).toEqual('chunked');
|
expect(res.headers.get('Transfer-Encoding')).toEqual('chunked');
|
||||||
expect(res.headers !.get('Connection')).toEqual('keep-alive');
|
expect(res.headers.get('Connection')).toEqual('keep-alive');
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ export function main() {
|
||||||
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
backend.connections.subscribe((c: MockConnection) => c.mockRespond(baseResponse));
|
||||||
http.request('http://basic.connection')
|
http.request('http://basic.connection')
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(res: Response) => { expect(res.text()).toBe('base response'); }, null !,
|
(res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||||
() => { async.done(); });
|
() => { async.done(); });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ export function main() {
|
||||||
});
|
});
|
||||||
http.request('http://basic.connection')
|
http.request('http://basic.connection')
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(res: Response) => { expect(res.text()).toBe('base response'); }, null !,
|
(res: Response) => { expect(res.text()).toBe('base response'); }, null,
|
||||||
() => { async.done(); });
|
() => { async.done(); });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,7 @@ export function main() {
|
||||||
describe('Request', () => {
|
describe('Request', () => {
|
||||||
describe('detectContentType', () => {
|
describe('detectContentType', () => {
|
||||||
it('should return ContentType.NONE', () => {
|
it('should return ContentType.NONE', () => {
|
||||||
const req =
|
const req = new Request(new RequestOptions({url: 'test', method: 'GET', body: null}));
|
||||||
new Request(new RequestOptions({url: 'test', method: 'GET', body: null}) as any);
|
|
||||||
|
|
||||||
expect(req.detectContentType()).toEqual(ContentType.NONE);
|
expect(req.detectContentType()).toEqual(ContentType.NONE);
|
||||||
});
|
});
|
||||||
|
@ -29,7 +28,7 @@ export function main() {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
body: null,
|
body: null,
|
||||||
headers: new Headers({'content-type': 'application/json'})
|
headers: new Headers({'content-type': 'application/json'})
|
||||||
}) as any);
|
}));
|
||||||
|
|
||||||
expect(req.detectContentType()).toEqual(ContentType.JSON);
|
expect(req.detectContentType()).toEqual(ContentType.JSON);
|
||||||
});
|
});
|
||||||
|
@ -40,7 +39,7 @@ export function main() {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
body: null,
|
body: null,
|
||||||
headers: new Headers({'content-type': 'application/x-www-form-urlencoded'})
|
headers: new Headers({'content-type': 'application/x-www-form-urlencoded'})
|
||||||
}) as any);
|
}));
|
||||||
|
|
||||||
expect(req.detectContentType()).toEqual(ContentType.FORM);
|
expect(req.detectContentType()).toEqual(ContentType.FORM);
|
||||||
});
|
});
|
||||||
|
@ -51,7 +50,7 @@ export function main() {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
body: null,
|
body: null,
|
||||||
headers: new Headers({'content-type': 'multipart/form-data'})
|
headers: new Headers({'content-type': 'multipart/form-data'})
|
||||||
}) as any);
|
}));
|
||||||
|
|
||||||
expect(req.detectContentType()).toEqual(ContentType.FORM_DATA);
|
expect(req.detectContentType()).toEqual(ContentType.FORM_DATA);
|
||||||
});
|
});
|
||||||
|
@ -62,7 +61,7 @@ export function main() {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
body: null,
|
body: null,
|
||||||
headers: new Headers({'content-type': 'text/plain'})
|
headers: new Headers({'content-type': 'text/plain'})
|
||||||
}) as any);
|
}));
|
||||||
|
|
||||||
expect(req.detectContentType()).toEqual(ContentType.TEXT);
|
expect(req.detectContentType()).toEqual(ContentType.TEXT);
|
||||||
});
|
});
|
||||||
|
@ -73,7 +72,7 @@ export function main() {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
body: null,
|
body: null,
|
||||||
headers: new Headers({'content-type': 'application/octet-stream'})
|
headers: new Headers({'content-type': 'application/octet-stream'})
|
||||||
}) as any);
|
}));
|
||||||
|
|
||||||
expect(req.detectContentType()).toEqual(ContentType.BLOB);
|
expect(req.detectContentType()).toEqual(ContentType.BLOB);
|
||||||
});
|
});
|
||||||
|
@ -84,7 +83,7 @@ export function main() {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
body: new ArrayBuffer(1),
|
body: new ArrayBuffer(1),
|
||||||
headers: new Headers({'content-type': 'application/octet-stream'})
|
headers: new Headers({'content-type': 'application/octet-stream'})
|
||||||
}) as any);
|
}));
|
||||||
|
|
||||||
expect(req.detectContentType()).toEqual(ContentType.ARRAY_BUFFER);
|
expect(req.detectContentType()).toEqual(ContentType.ARRAY_BUFFER);
|
||||||
});
|
});
|
||||||
|
@ -96,7 +95,7 @@ export function main() {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
body: null,
|
body: null,
|
||||||
headers: new Headers({'content-type': 'application/json'})
|
headers: new Headers({'content-type': 'application/json'})
|
||||||
}) as any);
|
}));
|
||||||
|
|
||||||
expect(req.text()).toEqual('');
|
expect(req.text()).toEqual('');
|
||||||
});
|
});
|
||||||
|
@ -105,7 +104,7 @@ export function main() {
|
||||||
const reqOptions = new RequestOptions(
|
const reqOptions = new RequestOptions(
|
||||||
{url: 'test', method: 'GET', headers: new Headers({'content-type': 'application/json'})});
|
{url: 'test', method: 'GET', headers: new Headers({'content-type': 'application/json'})});
|
||||||
delete reqOptions.body;
|
delete reqOptions.body;
|
||||||
const req = new Request(reqOptions as any);
|
const req = new Request(reqOptions);
|
||||||
|
|
||||||
expect(req.text()).toEqual('');
|
expect(req.text()).toEqual('');
|
||||||
});
|
});
|
||||||
|
|
|
@ -151,19 +151,19 @@ export function main() {
|
||||||
|
|
||||||
it('should remove the parameter when set to undefined or null', () => {
|
it('should remove the parameter when set to undefined or null', () => {
|
||||||
const params = new URLSearchParams('q=Q');
|
const params = new URLSearchParams('q=Q');
|
||||||
params.set('q', undefined !);
|
params.set('q', undefined);
|
||||||
expect(params.has('q')).toBe(false);
|
expect(params.has('q')).toBe(false);
|
||||||
expect(params.toString()).toEqual('');
|
expect(params.toString()).toEqual('');
|
||||||
params.set('q', null !);
|
params.set('q', null);
|
||||||
expect(params.has('q')).toBe(false);
|
expect(params.has('q')).toBe(false);
|
||||||
expect(params.toString()).toEqual('');
|
expect(params.toString()).toEqual('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore the value when append undefined or null', () => {
|
it('should ignore the value when append undefined or null', () => {
|
||||||
const params = new URLSearchParams('q=Q');
|
const params = new URLSearchParams('q=Q');
|
||||||
params.append('q', undefined !);
|
params.append('q', undefined);
|
||||||
expect(params.toString()).toEqual('q=Q');
|
expect(params.toString()).toEqual('q=Q');
|
||||||
params.append('q', null !);
|
params.append('q', null);
|
||||||
expect(params.toString()).toEqual('q=Q');
|
expect(params.toString()).toEqual('q=Q');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,13 @@ export declare class CookieXSRFStrategy implements XSRFStrategy {
|
||||||
export declare class Headers {
|
export declare class Headers {
|
||||||
constructor(headers?: Headers | {
|
constructor(headers?: Headers | {
|
||||||
[name: string]: any;
|
[name: string]: any;
|
||||||
} | null);
|
});
|
||||||
append(name: string, value: string): void;
|
append(name: string, value: string): void;
|
||||||
delete(name: string): void;
|
delete(name: string): void;
|
||||||
entries(): void;
|
entries(): void;
|
||||||
forEach(fn: (values: string[], name: string | undefined, headers: Map<string, string[]>) => void): void;
|
forEach(fn: (values: string[], name: string, headers: Map<string, string[]>) => void): void;
|
||||||
get(name: string): string | null;
|
get(name: string): string;
|
||||||
getAll(name: string): string[] | null;
|
getAll(name: string): string[];
|
||||||
has(name: string): boolean;
|
has(name: string): boolean;
|
||||||
keys(): string[];
|
keys(): string[];
|
||||||
set(name: string, value: string | string[]): void;
|
set(name: string, value: string | string[]): void;
|
||||||
|
@ -137,13 +137,13 @@ export declare enum RequestMethod {
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class RequestOptions {
|
export declare class RequestOptions {
|
||||||
body: any;
|
body: any;
|
||||||
headers: Headers | null;
|
headers: Headers;
|
||||||
method: RequestMethod | string | null;
|
method: RequestMethod | string;
|
||||||
params: URLSearchParams;
|
params: URLSearchParams;
|
||||||
responseType: ResponseContentType | null;
|
responseType: ResponseContentType;
|
||||||
/** @deprecated */ search: URLSearchParams;
|
/** @deprecated */ search: URLSearchParams;
|
||||||
url: string | null;
|
url: string;
|
||||||
withCredentials: boolean | null;
|
withCredentials: boolean;
|
||||||
constructor({method, headers, body, url, search, params, withCredentials, responseType}?: RequestOptionsArgs);
|
constructor({method, headers, body, url, search, params, withCredentials, responseType}?: RequestOptionsArgs);
|
||||||
merge(options?: RequestOptionsArgs): RequestOptions;
|
merge(options?: RequestOptionsArgs): RequestOptions;
|
||||||
}
|
}
|
||||||
|
@ -151,26 +151,26 @@ export declare class RequestOptions {
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export interface RequestOptionsArgs {
|
export interface RequestOptionsArgs {
|
||||||
body?: any;
|
body?: any;
|
||||||
headers?: Headers | null;
|
headers?: Headers;
|
||||||
method?: string | RequestMethod | null;
|
method?: string | RequestMethod;
|
||||||
params?: string | URLSearchParams | {
|
params?: string | URLSearchParams | {
|
||||||
[key: string]: any | any[];
|
[key: string]: any | any[];
|
||||||
} | null;
|
};
|
||||||
responseType?: ResponseContentType | null;
|
responseType?: ResponseContentType;
|
||||||
/** @deprecated */ search?: string | URLSearchParams | {
|
/** @deprecated */ search?: string | URLSearchParams | {
|
||||||
[key: string]: any | any[];
|
[key: string]: any | any[];
|
||||||
} | null;
|
};
|
||||||
url?: string | null;
|
url?: string;
|
||||||
withCredentials?: boolean | null;
|
withCredentials?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class Response extends Body {
|
export declare class Response extends Body {
|
||||||
bytesLoaded: number;
|
bytesLoaded: number;
|
||||||
headers: Headers | null;
|
headers: Headers;
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
status: number;
|
status: number;
|
||||||
statusText: string | null;
|
statusText: string;
|
||||||
totalBytes: number;
|
totalBytes: number;
|
||||||
type: ResponseType;
|
type: ResponseType;
|
||||||
url: string;
|
url: string;
|
||||||
|
@ -188,22 +188,22 @@ export declare enum ResponseContentType {
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class ResponseOptions {
|
export declare class ResponseOptions {
|
||||||
body: string | Object | ArrayBuffer | Blob | null;
|
body: string | Object | ArrayBuffer | Blob;
|
||||||
headers: Headers | null;
|
headers: Headers;
|
||||||
status: number | null;
|
status: number;
|
||||||
url: string | null;
|
url: string;
|
||||||
constructor({body, status, headers, statusText, type, url}?: ResponseOptionsArgs);
|
constructor({body, status, headers, statusText, type, url}?: ResponseOptionsArgs);
|
||||||
merge(options?: ResponseOptionsArgs): ResponseOptions;
|
merge(options?: ResponseOptionsArgs): ResponseOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export interface ResponseOptionsArgs {
|
export interface ResponseOptionsArgs {
|
||||||
body?: string | Object | FormData | ArrayBuffer | Blob | null;
|
body?: string | Object | FormData | ArrayBuffer | Blob;
|
||||||
headers?: Headers | null;
|
headers?: Headers;
|
||||||
status?: number | null;
|
status?: number;
|
||||||
statusText?: string | null;
|
statusText?: string;
|
||||||
type?: ResponseType | null;
|
type?: ResponseType;
|
||||||
url?: string | null;
|
url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
|
@ -224,7 +224,7 @@ export declare class URLSearchParams {
|
||||||
appendAll(searchParams: URLSearchParams): void;
|
appendAll(searchParams: URLSearchParams): void;
|
||||||
clone(): URLSearchParams;
|
clone(): URLSearchParams;
|
||||||
delete(param: string): void;
|
delete(param: string): void;
|
||||||
get(param: string): string | null;
|
get(param: string): string;
|
||||||
getAll(param: string): string[];
|
getAll(param: string): string[];
|
||||||
has(param: string): boolean;
|
has(param: string): boolean;
|
||||||
replaceAll(searchParams: URLSearchParams): void;
|
replaceAll(searchParams: URLSearchParams): void;
|
||||||
|
|
Loading…
Reference in New Issue