Adds HTTPResponse object and lazy loading text and JSON
This commit is contained in:
21
src/cloud-code/HTTPResponse.js
Normal file
21
src/cloud-code/HTTPResponse.js
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
export default class HTTPResponse {
|
||||
constructor(response) {
|
||||
this.status = response.statusCode;
|
||||
this.headers = response.headers;
|
||||
this.buffer = response.body;
|
||||
this.cookies = response.headers["set-cookie"];
|
||||
}
|
||||
|
||||
get text() {
|
||||
return this.buffer.toString('utf-8');
|
||||
}
|
||||
get data() {
|
||||
if (!this._data) {
|
||||
try {
|
||||
this._data = JSON.parse(this.text);
|
||||
} catch (e) {}
|
||||
}
|
||||
return this._data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user