Skip to content

Commit

Permalink
feat: convert header names to lowercase (nuxt/http#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed May 22, 2019
1 parent 90e8c13 commit 2e514a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/plugin.js
Expand Up @@ -4,6 +4,8 @@ import Axios from 'axios'
// Axios.prototype cannot be modified
const axiosExtra = {
setHeader (name, value, scopes = 'common') {
name = name.toLowerCase()

for (let scope of Array.isArray(scopes) ? scopes : [ scopes ]) {
if (!value) {
delete this.defaults.headers[scope][name];
Expand All @@ -14,7 +16,7 @@ const axiosExtra = {
},
setToken (token, type, scopes = 'common') {
const value = !token ? null : (type ? type + ' ' : '') + token
this.setHeader('Authorization', value, scopes)
this.setHeader('authorization', value, scopes)
},
onRequest(fn) {
this.interceptors.request.use(config => fn(config) || config)
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/pages/ssr.vue
Expand Up @@ -12,7 +12,7 @@ let reqCtr = 1
export default {
computed: {
axiosSessionId() {
return this.$axios.defaults.headers.common.sessionId
return this.$axios.defaults.headers.common.sessionid
},
axiosEncoding() {
Expand Down

0 comments on commit 2e514a4

Please sign in to comment.