Skip to content

Commit a51f16b

Browse files
authored
fix(ngApimockHandler): fix timeouts issues for POST or PUT methods when passThrough is selected (passTrough does not have to wait for the request end) (#27)
1 parent 138c60b commit a51f16b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lib/ngApimockHandler.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ abstract class NgApimockHandler implements Handler {
7070
requestDataChunks.push(rawData);
7171
});
7272

73-
request.on('end', () => {
74-
payload = Buffer.concat(requestDataChunks).toString();
7573

76-
if (mockResponse !== undefined) {
74+
if (mockResponse !== undefined) {
75+
request.on('end', () => {
76+
payload = Buffer.concat(requestDataChunks).toString();
77+
7778
if (this.getEcho(registry, match.identifier, ngApimockId)) {
7879
console.log(match.method + ' request made on \'' + match.expression + '\' with payload: ', payload);
7980
}
@@ -112,9 +113,13 @@ abstract class NgApimockHandler implements Handler {
112113
} else {
113114
sendResponse();
114115
}
115-
} else {
116-
// remove the recording header to stop recording after this call succeeds
117-
if (registry.record && !request.headers.record) {
116+
});
117+
} else {
118+
// remove the recording header to stop recording after this call succeeds
119+
if (registry.record && !request.headers.record) {
120+
request.on('end', () => {
121+
payload = Buffer.concat(requestDataChunks).toString();
122+
118123
const headers = request.headers;
119124
const host = <string>headers.host;
120125
const options = {
@@ -140,11 +145,11 @@ abstract class NgApimockHandler implements Handler {
140145
response.end(e);
141146
});
142147
req.end();
143-
} else {
144-
next();
145-
}
148+
});
149+
} else {
150+
next();
146151
}
147-
});
152+
}
148153
} else {
149154
next();
150155
}

0 commit comments

Comments
 (0)