refactor: use zero for empty response content length
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
+3
-3
@@ -245,13 +245,13 @@ describe('MiddlewareFactory', () => {
|
||||
it('should log incoming requests', async () => {
|
||||
const app = express();
|
||||
app.use(middleware.logging());
|
||||
app.get('/', (_req, res) => res.send('Hello World'));
|
||||
app.get('/', (_req, res) => res.send(''));
|
||||
|
||||
await request(app).get('/').expect(200);
|
||||
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
expect.stringContaining(
|
||||
'[2024-11-20T00:00:00.000Z] "GET / HTTP/1.1" 200 11 "-" "-"',
|
||||
'[2024-11-20T00:00:00.000Z] "GET / HTTP/1.1" 200 0 "-" "-"',
|
||||
),
|
||||
{
|
||||
type: 'incomingRequest',
|
||||
@@ -260,7 +260,7 @@ describe('MiddlewareFactory', () => {
|
||||
url: '/',
|
||||
status: 200,
|
||||
httpVersion: '1.1',
|
||||
contentLength: 11,
|
||||
contentLength: 0,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -182,9 +182,9 @@ export class MiddlewareFactory {
|
||||
logger.info(
|
||||
`[${meta.date}] "${meta.method} ${meta.url} HTTP/${
|
||||
meta.httpVersion
|
||||
}" ${meta.status} ${meta.contentLength} "${meta.referrer ?? '-'}" "${
|
||||
meta.userAgent ?? '-'
|
||||
}"`,
|
||||
}" ${meta.status} ${meta.contentLength ?? 0} "${
|
||||
meta.referrer ?? '-'
|
||||
}" "${meta.userAgent ?? '-'}"`,
|
||||
{
|
||||
type: 'incomingRequest',
|
||||
...meta,
|
||||
|
||||
Reference in New Issue
Block a user