@belmonddev/catch-request-express-middleware 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +7 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -58,7 +58,10 @@ const catchHttpResponse = (reqObject, responseCb) => {
|
|
|
58
58
|
|
|
59
59
|
const overrideHttpModule = (httpModule, requestSentCb) => {
|
|
60
60
|
override(httpModule, 'request', (reqObject, request) => {
|
|
61
|
-
const contentLength = getHeaderValue(
|
|
61
|
+
const contentLength = getHeaderValue(
|
|
62
|
+
request.headers || {},
|
|
63
|
+
'content-length'
|
|
64
|
+
);
|
|
62
65
|
const requestHasBody = !!contentLength;
|
|
63
66
|
const params = Object.fromEntries(
|
|
64
67
|
new URLSearchParams(request.query).entries()
|
|
@@ -108,11 +111,11 @@ const callReceivedCbs = (req, res, requestReceivedCb, body) => {
|
|
|
108
111
|
});
|
|
109
112
|
|
|
110
113
|
if (responseCb) {
|
|
111
|
-
|
|
112
|
-
if (
|
|
114
|
+
res.setMaxListeners(100);
|
|
115
|
+
if (res.writableFinished) {
|
|
113
116
|
callResponseCb(responseCb, res);
|
|
114
117
|
} else {
|
|
115
|
-
|
|
118
|
+
res.on('close', () => {
|
|
116
119
|
callResponseCb(responseCb, res);
|
|
117
120
|
});
|
|
118
121
|
}
|
|
@@ -132,7 +135,6 @@ const catchExpressReceivedRequest = (req, res, requestReceivedCb) => {
|
|
|
132
135
|
if (!res.bodyWritten.length) {
|
|
133
136
|
res.bodyWritten = firstData.split('\r\n\r\n')?.[1];
|
|
134
137
|
}
|
|
135
|
-
req.socketClosed = true;
|
|
136
138
|
}
|
|
137
139
|
});
|
|
138
140
|
|