From 7ad6645d8a00089c5b6c48b976f147589fe70c13 Mon Sep 17 00:00:00 2001 From: Pim Date: Tue, 21 May 2019 23:20:04 +0200 Subject: [PATCH] feat: convert header names to lowercase (#45) --- lib/plugin.js | 9 +++++++++ test/fixture/pages/ssr.vue | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/plugin.js b/lib/plugin.js index e193d78..56a576c 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -2,6 +2,9 @@ import KY from 'ky-universal' class HTTP { constructor(defaults, ky = KY) { + const headers = defaults.headers + delete defaults.headers + this._defaults = { hooks: {}, headers: {}, @@ -9,9 +12,15 @@ class HTTP { ...defaults } this._ky = ky + + for (const name in headers) { + this.setHeader(name, headers[name]) + } } setHeader(name, value) { + name = name.toLowerCase() + if (!value) { delete this._defaults.headers[name]; } else { diff --git a/test/fixture/pages/ssr.vue b/test/fixture/pages/ssr.vue index 217ac36..d8771b1 100644 --- a/test/fixture/pages/ssr.vue +++ b/test/fixture/pages/ssr.vue @@ -12,7 +12,7 @@ let reqCtr = 1 export default { computed: { httpSessionId() { - return this.$http._defaults.headers.sessionId + return this.$http._defaults.headers.sessionid }, httpEncoding() {