1 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
|
3 |
|
4 | import { WebResourceLike } from "./webResource";
|
5 | import { HttpHeadersLike } from "./httpHeaders";
|
6 |
|
7 | /**
|
8 | * The properties on an HTTP response which will always be present.
|
9 | */
|
10 | export interface HttpResponse {
|
11 | /**
|
12 | * The raw request
|
13 | */
|
14 | request: WebResourceLike;
|
15 |
|
16 | /**
|
17 | * The HTTP response status (e.g. 200)
|
18 | */
|
19 | status: number;
|
20 |
|
21 | /**
|
22 | * The HTTP response headers.
|
23 | */
|
24 | headers: HttpHeadersLike;
|
25 | }
|
26 |
|
27 | declare global {
|
28 | /**
|
29 | * Stub declaration of the browser-only Blob type.
|
30 | * Full type information can be obtained by including "lib": ["dom"] in tsconfig.json.
|
31 | */
|
32 | interface Blob {}
|
33 | }
|
34 |
|
35 | /**
|
36 | * Wrapper object for http request and response. Deserialized object is stored in
|
37 | * the `parsedBody` property when the response body is received in JSON or XML.
|
38 | */
|
39 | export interface HttpOperationResponse extends HttpResponse {
|
40 | /**
|
41 | * The parsed HTTP response headers.
|
42 | */
|
43 | parsedHeaders?: { [key: string]: any };
|
44 |
|
45 | /**
|
46 | * The response body as text (string format)
|
47 | */
|
48 | bodyAsText?: string | null;
|
49 |
|
50 | /**
|
51 | * The response body as parsed JSON or XML
|
52 | */
|
53 | parsedBody?: any;
|
54 |
|
55 | /**
|
56 | * BROWSER ONLY
|
57 | *
|
58 | * The response body as a browser Blob.
|
59 | * Always undefined in node.js.
|
60 | */
|
61 | blobBody?: Promise<Blob>;
|
62 |
|
63 | /**
|
64 | * NODEJS ONLY
|
65 | *
|
66 | * The response body as a node.js Readable stream.
|
67 | * Always undefined in the browser.
|
68 | */
|
69 | readableStreamBody?: NodeJS.ReadableStream;
|
70 |
|
71 | /**
|
72 | * The redirected property indicates whether the response is the result of a request which was redirected.
|
73 | */
|
74 | redirected?: boolean;
|
75 |
|
76 | /**
|
77 | * The url property contains the URL of the response. The value will be the final URL obtained after any redirects.
|
78 | */
|
79 | url?: string;
|
80 | }
|
81 |
|
82 | /**
|
83 | * The flattened response to a REST call.
|
84 | * Contains the underlying HttpOperationResponse as well as
|
85 | * the merged properties of the parsedBody, parsedHeaders, etc.
|
86 | */
|
87 | export interface RestResponse {
|
88 | /**
|
89 | * The underlying HTTP response containing both raw and deserialized response data.
|
90 | */
|
91 | _response: HttpOperationResponse;
|
92 |
|
93 | [key: string]: any;
|
94 | }
|