projects
/
squeep-api-dingus
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
simplify parameter objects slightly
[squeep-api-dingus]
/
lib
/
dingus.js
diff --git
a/lib/dingus.js
b/lib/dingus.js
index 4eded66a727e1d831e7249b462abb3d5da50fa17..3ca710e463db4fe614f469ea227b09bbc41e8325 100644
(file)
--- a/
lib/dingus.js
+++ b/
lib/dingus.js
@@
-349,8
+349,9
@@
class Dingus {
* Return all body data from a request.
* @param {http.ClientRequest} req
* @param {Number=} maximumBodySize
* Return all body data from a request.
* @param {http.ClientRequest} req
* @param {Number=} maximumBodySize
+ * @param {Boolean=} toString
*/
*/
- async bodyData(req, maximumBodySize) {
+ async bodyData(req, maximumBodySize
, toString = true
) {
const _scope = _fileScope('bodyData');
return new Promise((resolve, reject) => {
const body = [];
const _scope = _fileScope('bodyData');
return new Promise((resolve, reject) => {
const body = [];
@@
-363,7
+364,10
@@
class Dingus {
reject(new ResponseError(Enum.ErrorResponse.RequestEntityTooLarge));
}
});
reject(new ResponseError(Enum.ErrorResponse.RequestEntityTooLarge));
}
});
- req.on('end', () => resolve(Buffer.concat(body).toString()));
+ req.on('end', () => {
+ const bodyBuffer = Buffer.concat(body);
+ resolve(toString ? bodyBuffer.toString() : bodyBuffer);
+ });
req.on('error', (e) => {
this.logger.error(_scope, 'failed', { error: e });
reject(e);
req.on('error', (e) => {
this.logger.error(_scope, 'failed', { error: e });
reject(e);