Skip to content

Commit

Permalink
server: send response to client with res.end()
Browse files Browse the repository at this point in the history
Using res.end() to write result instead of res.write() followed by
res.end() will cause node not to use chunked encoding and include
Content-Length header. (See nodejs/node#26005) This small distinction is
important with some client. For example, Windows 10's MDM enrollment
system will not accept chunked response
(https://docs.microsoft.com/en-us/windows/client-management/mdm/on-premise-authentication-device-enrollment).

This might improve compatibility with some other clients, too. However,
there's a small chance that some client may expect the response to be
chunked.
  • Loading branch information
peat-psuwit committed Feb 8, 2019
1 parent 5b45068 commit d9ed4b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/server.js
Expand Up @@ -147,8 +147,7 @@ Server.prototype._processRequestXml = function (req, res, xml) {
if (statusCode) {
res.statusCode = statusCode;
}
res.write(result);
res.end();
res.end(result);
if (typeof self.log === 'function') {
self.log("replied", result);
}
Expand All @@ -157,17 +156,15 @@ Server.prototype._processRequestXml = function (req, res, xml) {
if (err.Fault !== undefined) {
return self._sendError(err.Fault, function (result, statusCode) {
res.statusCode = statusCode || 500;
res.write(result);
res.end();
res.end(result);
if (typeof self.log === 'function') {
self.log("error", err);
}
}, new Date().toISOString());
} else {
error = err.stack ? (self.suppressStack === true ? err.message : err.stack) : err;
res.statusCode = 500;
res.write(error);
res.end();
res.end(error);
if (typeof self.log === 'function') {
self.log("error", error);
}
Expand Down
19 changes: 19 additions & 0 deletions test/server-test.js
Expand Up @@ -483,6 +483,25 @@ describe('SOAP Server', function() {
});
});

it('should not use chunked encoding and return Content-Length header', function(done) {
soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
var clientArgs = { tickerSymbol: 'AAPL'};

assert.ifError(err);

client.on('response', function(body, response, eid) {
var headers = response.headers;
assert.notEqual(headers['content-length'], undefined);
assert.equal(headers['transfer-encoding'], undefined);
})

client.GetLastTradePrice(clientArgs, function(err, result, raw, headers) {
assert.ifError(err);
done();
});
});
});

// NOTE: this is actually a -client- test
/*
it('should return a valid error if the server stops responding': function(done) {
Expand Down

0 comments on commit d9ed4b5

Please sign in to comment.