Skip to content
Merged
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
13 changes: 13 additions & 0 deletions lib/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ const api = {
request.serverAccessLog.analyticsUserName = authNames.userName;
}
if (apiMethod === 'objectPut' || apiMethod === 'objectPutPart') {
const setStartTurnAroundTime = () => {
if (request.serverAccessLog) {
request.serverAccessLog.startTurnAroundTime = process.hrtime.bigint();
}
};
// For 0-byte uploads, downstream handlers do not consume
// the request stream, so 'end' never fires. Set
Comment on lines +271 to +272
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, sounds like a bug at first that the request stream is not consumed, do you happen to know if there's a good reason to be so?

Copy link
Copy Markdown
Contributor Author

@dvasilas dvasilas Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an optimization:

// startTurnAroundTime synchronously in that case.
if (request.headers['content-length'] === '0') {
setStartTurnAroundTime();
} else {
request.on('end', setStartTurnAroundTime);
}
return next(null, userInfo, authorizationResults, streamingV4Params, infos);
}
// issue 100 Continue to the client
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,40 @@ describe('api.callApiMethod', () => {
api.callApiMethod('multipartDelete', request, response, log);
});

['objectPut', 'objectPutPart'].forEach(method => {
it(`should set startTurnAroundTime on request end for ${method}`, done => {
sandbox.stub(api, method).callsFake(
(userInfo, _request, streamingV4Params, _log, cb) => {
request.on('end', () => {
assert.strictEqual(typeof request.serverAccessLog.startTurnAroundTime, 'bigint');
cb();
});
request.resume();
});
request.objectKey = 'testobject';
request.serverAccessLog = {};
api.callApiMethod(method, request, response, log, err => {
assert.ifError(err);
done();
});
});

it(`should set startTurnAroundTime synchronously for 0-byte ${method}`, done => {
sandbox.stub(api, method).callsFake(
(userInfo, _request, streamingV4Params, _log, cb) => {
assert.strictEqual(typeof request.serverAccessLog.startTurnAroundTime, 'bigint');
cb();
});
request.objectKey = 'testobject';
request.serverAccessLog = {};
request.headers = Object.assign({}, request.headers, { 'content-length': '0' });
api.callApiMethod(method, request, response, log, err => {
assert.ifError(err);
done();
});
});
});

describe('MD5 checksum validation', () => {
const methodsWithChecksumValidation = [
'bucketPutACL',
Expand Down
Loading