Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log cache hits distinct from fetch #273

Merged
merged 1 commit into from
Oct 14, 2024
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
16 changes: 12 additions & 4 deletions lib/check-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ function logRequest (method, res, startTime) {
const cacheStr = cacheStatus ? ` (cache ${cacheStatus})` : ''
const urlStr = cleanUrl(res.url)

log.http(
'fetch',
`${method.toUpperCase()} ${res.status} ${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}`
)
// If make-fetch-happen reports a cache hit, then there was no fetch
if (cacheStatus === 'hit') {
log.http(
'cache',
`${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}`
)
} else {
log.http(
'fetch',
`${method.toUpperCase()} ${res.status} ${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}`
)
}
}

function checkErrors (method, res, startTime, opts) {
Expand Down
4 changes: 2 additions & 2 deletions test/check-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ t.test('logs the value of x-local-cache-status when set', t => {
startTime,
})
res.body.emit('end')
t.equal(header, 'fetch')
t.equal(header, 'cache')
t.match(
msg,
/^GET 200 http:\/\/username:\*\*\*@example.com\/foo\/bar\/baz [0-9]+m?s \(cache hit\)$/
/^http:\/\/username:\*\*\*@example.com\/foo\/bar\/baz [0-9]+m?s \(cache hit\)$/
)
})