Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fix
- `res.write()` now returns the underlying write's boolean result, restoring backpressure signalling for streaming/SSE responses [@IanMcNelly](https://github.com/IanMcNelly).


## [4.0.3] - 2025-04-14

### Fix
Expand Down Expand Up @@ -55,4 +61,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed support for objects configuration in array fields from [@ugolas](https://github.com/ugolas).
- Fixed vulnerabilities from [@ugolas](https://github.com/ugolas).
- Replaced coverage reporter from istanbul to nyc from [@ugolas](https://github.com/ugolas).
- Removed support for node 6 from [@ugolas](https://github.com/ugolas).
- Removed support for node 6 from [@ugolas](https://github.com/ugolas).
4 changes: 2 additions & 2 deletions lib/express-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var audit = function (req, res, next) {

res.write = function (chunk) {
chunks.push(Buffer.from(chunk));
oldWrite.apply(res, arguments);
return oldWrite.apply(res, arguments);
};

// decorate response#json method from express
Expand Down Expand Up @@ -107,4 +107,4 @@ function setBodyLengthFields(options) {
const isValid = field => field && !isNaN(field) && field > 0;
options.request.maxBodyLength = !isValid(options.request.maxBodyLength) ? undefined : options.request.maxBodyLength;
options.response.maxBodyLength = !isValid(options.response.maxBodyLength) ? undefined : options.response.maxBodyLength;
}
}
18 changes: 17 additions & 1 deletion test/express-logger-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ describe('express-logger tests', function(){
should(auditResponseStub.calledOnce).eql(true);
should(res._bodyStr).eql('chunk');
});
it('Should return the underlying write() return value to preserve backpressure', function(){
var auditMethod = expressLogger();
// Start request
auditMethod(req, res, next);
should(next.calledOnce).eql(true);

// Underlying write() signals its buffer is full
resWriteStub.returns(false);
should(res.write('chunk')).eql(false);

// ... and that it has drained
resWriteStub.returns(true);
should(res.write('chunk')).eql(true);

should(resWriteStub.calledTwice).eql(true);
});
it('Should add body from end chunk to response', function(){
var auditMethod = expressLogger();
// Start request
Expand Down Expand Up @@ -236,4 +252,4 @@ describe('express-logger tests', function(){
should(res).eql(false);
})
});
});
});