1
|
/**
|
2
|
* @license
|
3
|
* Copyright Google Inc. All Rights Reserved.
|
4
|
*
|
5
|
* Use of this source code is governed by an MIT-style license that can be
|
6
|
* found in the LICENSE file at https://angular.io/license
|
7
|
*/
|
8
|
import { HttpHeaders } from './headers';
|
9
|
/**
|
10
|
* Type enumeration for the different kinds of `HttpEvent`.
|
11
|
*
|
12
|
* @experimental
|
13
|
*/
|
14
|
export declare enum HttpEventType {
|
15
|
/**
|
16
|
* The request was sent out over the wire.
|
17
|
*/
|
18
|
Sent = 0,
|
19
|
/**
|
20
|
* An upload progress event was received.
|
21
|
*/
|
22
|
UploadProgress = 1,
|
23
|
/**
|
24
|
* The response status code and headers were received.
|
25
|
*/
|
26
|
ResponseHeader = 2,
|
27
|
/**
|
28
|
* A download progress event was received.
|
29
|
*/
|
30
|
DownloadProgress = 3,
|
31
|
/**
|
32
|
* The full response including the body was received.
|
33
|
*/
|
34
|
Response = 4,
|
35
|
/**
|
36
|
* A custom event from an interceptor or a backend.
|
37
|
*/
|
38
|
User = 5,
|
39
|
}
|
40
|
/**
|
41
|
* Base interface for progress events.
|
42
|
*
|
43
|
* @experimental
|
44
|
*/
|
45
|
export interface HttpProgressEvent {
|
46
|
/**
|
47
|
* Progress event type is either upload or download.
|
48
|
*/
|
49
|
type: HttpEventType.DownloadProgress | HttpEventType.UploadProgress;
|
50
|
/**
|
51
|
* Number of bytes uploaded or downloaded.
|
52
|
*/
|
53
|
loaded: number;
|
54
|
/**
|
55
|
* Total number of bytes to upload or download. Depending on the request or
|
56
|
* response, this may not be computable and thus may not be present.
|
57
|
*/
|
58
|
total?: number;
|
59
|
}
|
60
|
/**
|
61
|
* A download progress event.
|
62
|
*
|
63
|
* @experimental
|
64
|
*/
|
65
|
export interface HttpDownloadProgressEvent extends HttpProgressEvent {
|
66
|
type: HttpEventType.DownloadProgress;
|
67
|
/**
|
68
|
* The partial response body as downloaded so far.
|
69
|
*
|
70
|
* Only present if the responseType was `text`.
|
71
|
*/
|
72
|
partialText?: string;
|
73
|
}
|
74
|
/**
|
75
|
* An upload progress event.
|
76
|
*
|
77
|
* @experimental
|
78
|
*/
|
79
|
export interface HttpUploadProgressEvent extends HttpProgressEvent {
|
80
|
type: HttpEventType.UploadProgress;
|
81
|
}
|
82
|
/**
|
83
|
* An event indicating that the request was sent to the server. Useful
|
84
|
* when a request may be retried multiple times, to distinguish between
|
85
|
* retries on the final event stream.
|
86
|
*
|
87
|
* @experimental
|
88
|
*/
|
89
|
export interface HttpSentEvent {
|
90
|
type: HttpEventType.Sent;
|
91
|
}
|
92
|
/**
|
93
|
* A user-defined event.
|
94
|
*
|
95
|
* Grouping all custom events under this type ensures they will be handled
|
96
|
* and forwarded by all implementations of interceptors.
|
97
|
*
|
98
|
* @experimental
|
99
|
*/
|
100
|
export interface HttpUserEvent<T> {
|
101
|
type: HttpEventType.User;
|
102
|
}
|
103
|
/**
|
104
|
* An error that represents a failed attempt to JSON.parse text coming back
|
105
|
* from the server.
|
106
|
*
|
107
|
* It bundles the Error object with the actual response body that failed to parse.
|
108
|
*
|
109
|
* @experimental
|
110
|
*/
|
111
|
export interface HttpJsonParseError {
|
112
|
error: Error;
|
113
|
text: string;
|
114
|
}
|
115
|
/**
|
116
|
* Union type for all possible events on the response stream.
|
117
|
*
|
118
|
* Typed according to the expected type of the response.
|
119
|
*
|
120
|
* @experimental
|
121
|
*/
|
122
|
export declare type HttpEvent<T> = HttpSentEvent | HttpHeaderResponse | HttpResponse<T> | HttpProgressEvent | HttpUserEvent<T>;
|
123
|
/**
|
124
|
* Base class for both `HttpResponse` and `HttpHeaderResponse`.
|
125
|
*
|
126
|
* @experimental
|
127
|
*/
|
128
|
export declare abstract class HttpResponseBase {
|
129
|
/**
|
130
|
* All response headers.
|
131
|
*/
|
132
|
readonly headers: HttpHeaders;
|
133
|
/**
|
134
|
* Response status code.
|
135
|
*/
|
136
|
readonly status: number;
|
137
|
/**
|
138
|
* Textual description of response status code.
|
139
|
*
|
140
|
* Do not depend on this.
|
141
|
*/
|
142
|
readonly statusText: string;
|
143
|
/**
|
144
|
* URL of the resource retrieved, or null if not available.
|
145
|
*/
|
146
|
readonly url: string | null;
|
147
|
/**
|
148
|
* Whether the status code falls in the 2xx range.
|
149
|
*/
|
150
|
readonly ok: boolean;
|
151
|
/**
|
152
|
* Type of the response, narrowed to either the full response or the header.
|
153
|
*/
|
154
|
readonly type: HttpEventType.Response | HttpEventType.ResponseHeader;
|
155
|
/**
|
156
|
* Super-constructor for all responses.
|
157
|
*
|
158
|
* The single parameter accepted is an initialization hash. Any properties
|
159
|
* of the response passed there will override the default values.
|
160
|
*/
|
161
|
constructor(init: {
|
162
|
headers?: HttpHeaders;
|
163
|
status?: number;
|
164
|
statusText?: string;
|
165
|
url?: string;
|
166
|
}, defaultStatus?: number, defaultStatusText?: string);
|
167
|
}
|
168
|
/**
|
169
|
* A partial HTTP response which only includes the status and header data,
|
170
|
* but no response body.
|
171
|
*
|
172
|
* `HttpHeaderResponse` is a `HttpEvent` available on the response
|
173
|
* event stream, only when progress events are requested.
|
174
|
*
|
175
|
* @experimental
|
176
|
*/
|
177
|
export declare class HttpHeaderResponse extends HttpResponseBase {
|
178
|
/**
|
179
|
* Create a new `HttpHeaderResponse` with the given parameters.
|
180
|
*/
|
181
|
constructor(init?: {
|
182
|
headers?: HttpHeaders;
|
183
|
status?: number;
|
184
|
statusText?: string;
|
185
|
url?: string;
|
186
|
});
|
187
|
readonly type: HttpEventType.ResponseHeader;
|
188
|
/**
|
189
|
* Copy this `HttpHeaderResponse`, overriding its contents with the
|
190
|
* given parameter hash.
|
191
|
*/
|
192
|
clone(update?: {
|
193
|
headers?: HttpHeaders;
|
194
|
status?: number;
|
195
|
statusText?: string;
|
196
|
url?: string;
|
197
|
}): HttpHeaderResponse;
|
198
|
}
|
199
|
/**
|
200
|
* A full HTTP response, including a typed response body (which may be `null`
|
201
|
* if one was not returned).
|
202
|
*
|
203
|
* `HttpResponse` is a `HttpEvent` available on the response event
|
204
|
* stream.
|
205
|
*
|
206
|
* @experimental
|
207
|
*/
|
208
|
export declare class HttpResponse<T> extends HttpResponseBase {
|
209
|
/**
|
210
|
* The response body, or `null` if one was not returned.
|
211
|
*/
|
212
|
readonly body: T | null;
|
213
|
/**
|
214
|
* Construct a new `HttpResponse`.
|
215
|
*/
|
216
|
constructor(init?: {
|
217
|
body?: T | null;
|
218
|
headers?: HttpHeaders;
|
219
|
status?: number;
|
220
|
statusText?: string;
|
221
|
url?: string;
|
222
|
});
|
223
|
readonly type: HttpEventType.Response;
|
224
|
clone(): HttpResponse<T>;
|
225
|
clone(update: {
|
226
|
headers?: HttpHeaders;
|
227
|
status?: number;
|
228
|
statusText?: string;
|
229
|
url?: string;
|
230
|
}): HttpResponse<T>;
|
231
|
clone<V>(update: {
|
232
|
body?: V | null;
|
233
|
headers?: HttpHeaders;
|
234
|
status?: number;
|
235
|
statusText?: string;
|
236
|
url?: string;
|
237
|
}): HttpResponse<V>;
|
238
|
}
|
239
|
/**
|
240
|
* A response that represents an error or failure, either from a
|
241
|
* non-successful HTTP status, an error while executing the request,
|
242
|
* or some other failure which occurred during the parsing of the response.
|
243
|
*
|
244
|
* Any error returned on the `Observable` response stream will be
|
245
|
* wrapped in an `HttpErrorResponse` to provide additional context about
|
246
|
* the state of the HTTP layer when the error occurred. The error property
|
247
|
* will contain either a wrapped Error object or the error response returned
|
248
|
* from the server.
|
249
|
*
|
250
|
* @experimental
|
251
|
*/
|
252
|
export declare class HttpErrorResponse extends HttpResponseBase implements Error {
|
253
|
readonly name: string;
|
254
|
readonly message: string;
|
255
|
readonly error: any | null;
|
256
|
/**
|
257
|
* Errors are never okay, even when the status code is in the 2xx success range.
|
258
|
*/
|
259
|
readonly ok: boolean;
|
260
|
constructor(init: {
|
261
|
error?: any;
|
262
|
headers?: HttpHeaders;
|
263
|
status?: number;
|
264
|
statusText?: string;
|
265
|
url?: string;
|
266
|
});
|
267
|
}
|