fix: correctly ignore brotli encoding on server-side (#180)

master
Alexander Lichter 2018-11-08 09:17:46 +00:00 committed by Pooya Parsa
parent ceabf1f1db
commit 4a52bfdc81
3 changed files with 39 additions and 19 deletions

View File

@ -168,10 +168,6 @@ export default (ctx, inject) => {
patch: {}
}
if (process.server) {
headers.common['Accept-Encoding'] = 'gzip, deflate'
}
const axiosOptions = {
baseURL,
headers
@ -183,6 +179,11 @@ export default (ctx, inject) => {
<% for (let h of options.proxyHeadersIgnore) { %>delete axiosOptions.headers.common['<%= h %>']
<% } %><% } %>
if (process.server) {
// Don't accept brotli encoding because Node can't parse it
axiosOptions.headers.common['Accept-Encoding'] = 'gzip, deflate'
}
// Create new axios instance
const axios = Axios.create(axiosOptions)

View File

@ -76,4 +76,17 @@ describe('axios module', () => {
expect(d).not.toBeNull()
expect(b).not.toBe(d)
})
test('ssr no brotli', async () => {
const makeReq = login =>
axios
.get(url('/ssr' + (login ? '?login' : '')))
.then(r => r.data)
.then(h => /encoding-\$(.*)\$/.exec(h))
.then(m => (m && m[1] ? m[1] : null))
const result = await makeReq()
expect(result).toBe('gzip, deflate')
})
})

View File

@ -1,22 +1,28 @@
<template>
<div>session-{{ axiosSessionId }}</div>
<div>
<div>session-{{ axiosSessionId }}</div>
<div>encoding-${{ axiosEncoding }}$</div>
</div>
</template>
<script>
// This will be intentially shared across requests
let reqCtr = 1
// This will be intentically shared across requests
let reqCtr = 1
export default {
async fetch ({ app, route }) {
let doLogin = route.query.login !== undefined
if (doLogin) {
app.$axios.setHeader('sessionId', reqCtr++)
}
},
computed: {
axiosSessionId () {
return this.$axios.defaults.headers.common.sessionId
export default {
async fetch ({app, route}) {
let doLogin = route.query.login !== undefined
if (doLogin) {
app.$axios.setHeader('sessionId', reqCtr++)
}
},
computed: {
axiosSessionId () {
return this.$axios.defaults.headers.common.sessionId
},
axiosEncoding () {
return this.$axios.defaults.headers.common['Accept-Encoding']
}
}
}
}
</script>
</script>