Revert "fix(http): Update types for TypeScript nullability support"
This reverts commit c36ec9bf60
.
Broke in G3.
This commit is contained in:
@ -10,7 +10,7 @@ import {Injectable} from '@angular/core';
|
||||
|
||||
let _nextRequestId = 0;
|
||||
export const JSONP_HOME = '__ng_jsonp__';
|
||||
let _jsonpConnections: {[key: string]: any}|null = null;
|
||||
let _jsonpConnections: {[key: string]: any} = null;
|
||||
|
||||
function _getJsonpConnections(): {[key: string]: any} {
|
||||
const w: {[key: string]: any} = typeof window == 'object' ? window : {};
|
||||
|
@ -115,7 +115,7 @@ export class XHRConnection implements Connection {
|
||||
if (!req.headers.has('Accept')) {
|
||||
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
|
||||
if (req.responseType != null && _xhr.responseType != null) {
|
||||
|
@ -44,11 +44,11 @@ export class RequestOptions {
|
||||
* Http method with which to execute a {@link Request}.
|
||||
* 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}.
|
||||
*/
|
||||
headers: Headers|null;
|
||||
headers: Headers;
|
||||
/**
|
||||
* 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: string|null;
|
||||
url: string;
|
||||
/**
|
||||
* Search parameters to be included in a {@link Request}.
|
||||
*/
|
||||
@ -72,11 +72,11 @@ export class RequestOptions {
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
responseType: ResponseContentType|null;
|
||||
responseType: ResponseContentType;
|
||||
|
||||
// TODO(Dzmitry): remove search when this.search is removed
|
||||
constructor(
|
||||
@ -128,8 +128,8 @@ export class RequestOptions {
|
||||
});
|
||||
}
|
||||
|
||||
private _mergeSearchParams(params?: string|URLSearchParams|{[key: string]: any | any[]}|
|
||||
null): URLSearchParams {
|
||||
private _mergeSearchParams(params: string|URLSearchParams|
|
||||
{[key: string]: any | any[]}): URLSearchParams {
|
||||
if (!params) return this.params;
|
||||
|
||||
if (params instanceof URLSearchParams) {
|
||||
|
@ -46,25 +46,25 @@ export class ResponseOptions {
|
||||
/**
|
||||
* 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}
|
||||
* associated with the response.
|
||||
*/
|
||||
status: number|null;
|
||||
status: number;
|
||||
/**
|
||||
* Response {@link Headers headers}
|
||||
*/
|
||||
headers: Headers|null;
|
||||
headers: Headers;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
statusText: string|null;
|
||||
statusText: string;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
type: ResponseType|null;
|
||||
url: string|null;
|
||||
type: ResponseType;
|
||||
url: string;
|
||||
constructor({body, status, headers, statusText, type, url}: ResponseOptionsArgs = {}) {
|
||||
this.body = body != null ? body : null;
|
||||
this.status = status != null ? status : null;
|
||||
|
@ -41,7 +41,7 @@ export class Headers {
|
||||
_normalizedNames: Map<string, string> = new Map();
|
||||
|
||||
// TODO(vicb): any -> string|string[]
|
||||
constructor(headers?: Headers|{[name: string]: any}|null) {
|
||||
constructor(headers?: Headers|{[name: string]: any}) {
|
||||
if (!headers) {
|
||||
return;
|
||||
}
|
||||
@ -100,8 +100,7 @@ export class Headers {
|
||||
this._headers.delete(lcName);
|
||||
}
|
||||
|
||||
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 {
|
||||
this._headers.forEach(
|
||||
(values, lcName) => fn(values, this._normalizedNames.get(lcName), this._headers));
|
||||
}
|
||||
@ -109,7 +108,7 @@ export class Headers {
|
||||
/**
|
||||
* Returns first header that matches given name.
|
||||
*/
|
||||
get(name: string): string|null {
|
||||
get(name: string): string {
|
||||
const values = this.getAll(name);
|
||||
|
||||
if (values === null) {
|
||||
@ -158,7 +157,7 @@ export class Headers {
|
||||
this._headers.forEach((values: string[], name: string) => {
|
||||
const split: string[] = [];
|
||||
values.forEach(v => split.push(...v.split(',')));
|
||||
serialized[this._normalizedNames.get(name) !] = split;
|
||||
serialized[this._normalizedNames.get(name)] = split;
|
||||
});
|
||||
|
||||
return serialized;
|
||||
@ -167,8 +166,8 @@ export class Headers {
|
||||
/**
|
||||
* Returns list of header values for a given name.
|
||||
*/
|
||||
getAll(name: string): string[]|null {
|
||||
return this.has(name) ? this._headers.get(name.toLowerCase()) || null : null;
|
||||
getAll(name: string): string[] {
|
||||
return this.has(name) ? this._headers.get(name.toLowerCase()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,10 +8,9 @@
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
import {RequestMethod} from './enums';
|
||||
import {ConnectionBackend, RequestArgs, RequestOptionsArgs} from './interfaces';
|
||||
import {ConnectionBackend, RequestOptionsArgs} from './interfaces';
|
||||
import {Request} from './static_request';
|
||||
import {Response} from './static_response';
|
||||
|
||||
@ -20,8 +19,8 @@ function httpRequest(backend: ConnectionBackend, request: Request): Observable<R
|
||||
}
|
||||
|
||||
function mergeOptions(
|
||||
defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs | undefined,
|
||||
method: RequestMethod, url: string): RequestArgs {
|
||||
defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs, method: RequestMethod,
|
||||
url: string): RequestOptions {
|
||||
const newOptions = defaultOpts;
|
||||
if (providedOpts) {
|
||||
// Hack so Dart can used named parameters
|
||||
@ -34,10 +33,10 @@ function mergeOptions(
|
||||
body: providedOpts.body,
|
||||
withCredentials: providedOpts.withCredentials,
|
||||
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 function getResponseURL(xhr: any): string|null {
|
||||
export function getResponseURL(xhr: any): string {
|
||||
if ('responseURL' in xhr) {
|
||||
return xhr.responseURL;
|
||||
}
|
||||
if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
|
||||
return xhr.getResponseHeader('X-Request-URL');
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
export function stringToArrayBuffer(input: String): ArrayBuffer {
|
||||
|
@ -46,21 +46,21 @@ export abstract class XSRFStrategy { abstract configureRequest(req: Request): vo
|
||||
* @experimental
|
||||
*/
|
||||
export interface RequestOptionsArgs {
|
||||
url?: string|null;
|
||||
method?: string|RequestMethod|null;
|
||||
url?: string;
|
||||
method?: string|RequestMethod;
|
||||
/** @deprecated from 4.0.0. Use params instead. */
|
||||
search?: string|URLSearchParams|{[key: string]: any | any[]}|null;
|
||||
params?: string|URLSearchParams|{[key: string]: any | any[]}|null;
|
||||
headers?: Headers|null;
|
||||
search?: string|URLSearchParams|{[key: string]: any | any[]};
|
||||
params?: string|URLSearchParams|{[key: string]: any | any[]};
|
||||
headers?: Headers;
|
||||
body?: any;
|
||||
withCredentials?: boolean|null;
|
||||
responseType?: ResponseContentType|null;
|
||||
withCredentials?: boolean;
|
||||
responseType?: ResponseContentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -69,10 +69,10 @@ export interface RequestArgs extends RequestOptionsArgs { url: string|null; }
|
||||
* @experimental
|
||||
*/
|
||||
export interface ResponseOptionsArgs {
|
||||
body?: string|Object|FormData|ArrayBuffer|Blob|null;
|
||||
status?: number|null;
|
||||
statusText?: string|null;
|
||||
headers?: Headers|null;
|
||||
type?: ResponseType|null;
|
||||
url?: string|null;
|
||||
body?: string|Object|FormData|ArrayBuffer|Blob;
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
headers?: Headers;
|
||||
type?: ResponseType;
|
||||
url?: string;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ export class Request extends Body {
|
||||
super();
|
||||
// TODO: assert that url is present
|
||||
const url = requestOptions.url;
|
||||
this.url = requestOptions.url !;
|
||||
this.url = requestOptions.url;
|
||||
if (requestOptions.params) {
|
||||
const params = requestOptions.params.toString();
|
||||
if (params.length > 0) {
|
||||
@ -88,13 +88,13 @@ export class Request extends Body {
|
||||
}
|
||||
}
|
||||
this._body = requestOptions.body;
|
||||
this.method = normalizeMethodName(requestOptions.method !);
|
||||
this.method = normalizeMethodName(requestOptions.method);
|
||||
// TODO(jeffbcross): implement behavior
|
||||
// Defaults to 'omit', consistent with browser
|
||||
this.headers = new Headers(requestOptions.headers);
|
||||
this.contentType = this.detectContentType();
|
||||
this.withCredentials = requestOptions.withCredentials !;
|
||||
this.responseType = requestOptions.responseType !;
|
||||
this.withCredentials = requestOptions.withCredentials;
|
||||
this.responseType = requestOptions.responseType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ export class Response extends Body {
|
||||
*
|
||||
* Defaults to "OK"
|
||||
*/
|
||||
statusText: string|null;
|
||||
statusText: string;
|
||||
/**
|
||||
* Non-standard property
|
||||
*
|
||||
@ -81,17 +81,17 @@ export class Response extends Body {
|
||||
* Headers object based on the `Headers` class in the [Fetch
|
||||
* Spec](https://fetch.spec.whatwg.org/#headers-class).
|
||||
*/
|
||||
headers: Headers|null;
|
||||
headers: Headers;
|
||||
|
||||
constructor(responseOptions: ResponseOptions) {
|
||||
super();
|
||||
this._body = responseOptions.body;
|
||||
this.status = responseOptions.status !;
|
||||
this.status = responseOptions.status;
|
||||
this.ok = (this.status >= 200 && this.status <= 299);
|
||||
this.statusText = responseOptions.statusText;
|
||||
this.headers = responseOptions.headers;
|
||||
this.type = responseOptions.type !;
|
||||
this.url = responseOptions.url !;
|
||||
this.type = responseOptions.type;
|
||||
this.url = responseOptions.url;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
@ -93,7 +93,7 @@ export class URLSearchParams {
|
||||
|
||||
has(param: string): boolean { return this.paramsMap.has(param); }
|
||||
|
||||
get(param: string): string|null {
|
||||
get(param: string): string {
|
||||
const storedParam = this.paramsMap.get(param);
|
||||
|
||||
return Array.isArray(storedParam) ? storedParam[0] : null;
|
||||
|
Reference in New Issue
Block a user