fix(vue-renderer): add vary header for ‍user-agent‍ in modern server mode (#5807)

This commit is contained in:
Pooya Parsa 2019-05-26 00:24:00 +04:30 committed by GitHub
parent a0958f03f4
commit 7e50fe744f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -109,4 +109,12 @@ export default class ModernRenderer extends SSRRenderer {
return linkTag.replace('rel="preload"', `rel="modulepreload"${cors}`).replace(legacyJsFile, modernJsFile)
})
}
async render(renderContext) {
const result = await super.render(renderContext)
if (this.isServerMode) {
renderContext.res.setHeader('Vary', 'User-Agent')
}
return result
}
}

View File

@ -68,6 +68,14 @@ describe('modern server mode', () => {
].join(', '))
})
test('Vary header should contain User-Agent', async () => {
const { headers: { vary } } = await rp(url('/'), {
resolveWithFullResponse: true,
headers: { 'user-agent': modernUA }
})
expect(vary).toContain('User-Agent')
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()