2017-09-13 19:42:16 +03:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
|
|
|
|
import { WebResource } from "./webResource";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper object for http request and response. Deserialized object is stored in
|
2017-10-25 20:30:16 +03:00
|
|
|
* the `bodyAsJson` property when the response body is received in JSON.
|
2017-09-13 19:42:16 +03:00
|
|
|
* @class
|
|
|
|
* Initializes a new instance of the HttpOperationResponse class.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
export class HttpOperationResponse {
|
|
|
|
/**
|
|
|
|
* The raw request
|
|
|
|
*/
|
|
|
|
request: WebResource;
|
|
|
|
/**
|
2017-10-25 20:30:16 +03:00
|
|
|
* The raw response. Please use the response directly when the response body is a ReadableStream.
|
2017-09-13 19:42:16 +03:00
|
|
|
*/
|
|
|
|
response: Response;
|
|
|
|
/**
|
|
|
|
* The response body as text (string format)
|
|
|
|
*/
|
|
|
|
bodyAsText: string | null;
|
|
|
|
/**
|
|
|
|
* The response body as parsed JSON
|
|
|
|
*/
|
|
|
|
bodyAsJson: { [key: string]: any } | Array<any> | string | number | boolean | null | void;
|
|
|
|
|
2017-10-25 20:30:16 +03:00
|
|
|
constructor(request: WebResource, response: Response) {
|
2017-09-13 19:42:16 +03:00
|
|
|
/**
|
|
|
|
* Reference to the original request object.
|
|
|
|
* [WebResource] object.
|
|
|
|
* @type {object}
|
|
|
|
*/
|
|
|
|
this.request = request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to the original response object.
|
|
|
|
* [ServerResponse] object.
|
|
|
|
* @type {object}
|
|
|
|
*/
|
|
|
|
this.response = response;
|
2017-10-25 20:30:16 +03:00
|
|
|
/* tslint:disable:no-null-keyword */
|
2017-09-13 19:42:16 +03:00
|
|
|
this.bodyAsText = null;
|
|
|
|
this.bodyAsJson = null;
|
|
|
|
}
|
|
|
|
}
|