Skip to content

Commit

Permalink
fix: ignore some headers when proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 27, 2020
1 parent bcc7d8d commit f99d313
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
22 changes: 21 additions & 1 deletion nuxt/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import path from 'path'

export default function NuxtMandeModule() {
const DEFAULT_OPTIONS = {
proxyHeadersIgnore: [
'accept',
'host',
'cf-ray',
'cf-connecting-ip',
'content-length',
'content-md5',
'content-type',
],
}

/** @type {import('@nuxt/types').Module} */
const MandeModule = function NuxtMandeModule(localOptions) {
// TODO: merge arrays properly. There is probably a package to handle this
const options = {
...DEFAULT_OPTIONS,
...localOptions,
}

this.addPlugin({
src: path.resolve(__dirname, 'plugin.js'),
fileName: 'mande.js',
options,
})
}
15 changes: 14 additions & 1 deletion nuxt/plugin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@

/** @type {import('@nuxt/types').Plugin} */
export default (ctx, inject) => {
function mande(wrappedFn, ...args) {
return wrappedFn(
/** @type {import('../src').MandeInstance} */
(api) => {
api.options.headers = { ...api.options.headers, ...ctx.req.headers }
const reqHeaders = { ...ctx.req.headers }

// @ts-ignore
for (let header of <%= serialize(options.proxyHeadersIgnore) %>) {
delete reqHeaders[header]
}

api.options.headers = { ...api.options.headers, ...reqHeaders }

if (process.server) {
// Don't accept brotli encoding because Node can't parse it
api.options.headers['accept-encoding'] = 'gzip, deflate'
}
},
...args
)
Expand Down

0 comments on commit f99d313

Please sign in to comment.