Skip to content

Commit

Permalink
fix: not send Server-Timing header if no timing info
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Feb 14, 2019
1 parent c6d8e8f commit d9a0b5f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/server/src/middleware/timing.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ export default options => (req, res, next) => {
onHeaders(res, () => {
res.timing.end('total')

res.setHeader(
'Server-Timing',
[]
.concat(res.getHeader('Server-Timing') || [])
.concat(res.timing.headers)
.join(', ')
)
if (res.timing.headers.length > 0) {
res.setHeader(
'Server-Timing',
[]
.concat(res.getHeader('Server-Timing') || [])
.concat(res.timing.headers)
.join(', ')
)
}
res.timing.clear()
})

next()
Expand All @@ -35,7 +38,9 @@ class ServerTiming extends Timer {

end(...args) {
const time = super.end(...args)
this.headers.push(this.formatHeader(time))
if (time) {
this.headers.push(this.formatHeader(time))
}
return time
}

Expand Down

0 comments on commit d9a0b5f

Please sign in to comment.