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
3 changes: 2 additions & 1 deletion packages/core/bin/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const createPrint = host => {
const printFooter = ({ duration, response }) => {
const headers = toPlainHeaders(response?.headers)
const time = prettyMs(duration)
const size = Number(headers['content-length']) || 0
const size =
Number(headers['content-length'] || headers['x-content-length']) || 0
const serverTiming = headers['server-timing']
const id = headers['x-request-id']
const edgeCacheStatus = headers['cf-cache-status']
Expand Down
31 changes: 31 additions & 0 deletions packages/core/test/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,37 @@ test('search footer reports the response size', async t => {
t.false(stderr.includes('0 B'))
})

test('search footer uses x-content-length when content-length is absent', async t => {
const body = JSON.stringify({
status: 'success',
data: { results: [{ title: 'The Matrix', url: 'https://example.com' }] }
})
const bytes = Buffer.byteLength(body)
const server = http.createServer((req, res) => {
res.statusCode = 200
res.setHeader('content-type', 'application/json')
res.setHeader('x-content-length', bytes)
res.end(body)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test still sends Content-Length

Low Severity

The new test never leaves content-length unset. Node.js adds that header when res.end is given a body, so the footer still reads content-length and the x-content-length fallback is not exercised. The test would pass without the production change.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f6fc41c. Configure here.

})
t.teardown(() => new Promise(resolve => server.close(resolve)))
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))
const endpoint = `http://127.0.0.1:${server.address().port}`

const { stderr } = await $('node', [
bin,
'search',
'--type',
'images',
'the matrix',
'--endpoint',
endpoint
])

t.true(stderr.includes('SUCCESS'), stderr)
t.true(stderr.includes(`${bytes} B`), stderr)
t.false(stderr.includes('0 B'))
})

test('logout removes the saved config file', async t => {
const { dir, env } = configHome('file-key-1')
const file = path.join(dir, 'microlink', 'config.json')
Expand Down