Skip to content

Forward all headers (missing http-x-requested-with Headers) #130

Closed
@LeonardoGentile

Description

@LeonardoGentile

Expected behavior

I'm using the proxy options in webpack configuration.
My webpack dev server is running at localhost:8888 and my backend is at localhost:8000.
What I was expecting is that all the HTTP HEADERS sent to the webpack dev server would have been forwarded to the proxy server at localhost:8000

Actual behavior

Actually some HTTP HEADERS are missing, at least the one I am interested in, that is: http-x-requested-with XMLHttpRequest. This header is never sent to the destination server and I'm wondering if it is by design or a bug.
The only way to make this work is to manually add this header in the proxy section of the webpack config headers: {'http-x-requested-with' : 'XMLHttpRequest' }

Setup

  • http-proxy-middleware: 0.17.2
  • server: webpack-dev-server@1.16.2

proxy middleware configuration

  proxy: {
      '/api/*': {
        target: 'http://localhost:8000',
        pathRewrite: {'^/api' : ''},
        secure: false,
        changeOrigin: true,
        headers: {
          'http-x-requested-with' : 'XMLHttpRequest'
        }
      }
    }

server mounting

Webpack devserver config

devServer: {
    contentBase: "./public",
    // do not print bundle build stats
    noInfo: true,
    // enable HMR
    hot: true,
    // embed the webpack-dev-server runtime into the bundle
    inline: true,
    // serve index.html in place of 404 responses to allow HTML5 history
    historyApiFallback: true,
    port: PORT,
    host: HOST,
    proxy: {
      '/api/*': {
        target: 'http://localhost:8000',
        pathRewrite: {'^/api' : ''},
        secure: false,
        changeOrigin: true,
        // manually adding this will add the header back and send it to the destination server
        // headers: {'http-x-requested-with' : 'XMLHttpRequest' }
      }
    }
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions