Skip to content
Permalink
Browse files

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

  • Loading branch information...
manniL authored and pi0 committed Nov 8, 2018
1 parent ceabf1f commit 4a52bfdc81ad0f82b142b226bc6026d67e56b5c6
Showing with 39 additions and 19 deletions.
  1. +5 −4 lib/plugin.template.js
  2. +13 −0 test/axios.test.js
  3. +21 −15 test/fixture/pages/ssr.vue
@@ -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)

@@ -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')
})
})
@@ -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>

0 comments on commit 4a52bfd

Please sign in to comment.
You can’t perform that action at this time.