villadora / express-http-proxy

Proxy middleware for express/connect
Other
1.22k stars 236 forks source link

Unable to change 'content-type' header of request #526

Closed harsh-niyo closed 1 month ago

harsh-niyo commented 1 year ago

I have written a proxy server using nestjs and express-rest-proxy. I want to change the content-type header of the request. I am using proxyReqOptDecorator to do the same, but it is not updating the header of the request. Is there something that I'm doing anything incorrectly or is this a bug?

Version - 2.0.0

Code sample:

const proxyMiddleware: ProxyMiddleware =
    app.get<ProxyMiddleware>(ProxyMiddleware);
  app.use(
    configService.get<string>('liquiLoans.path'),
    proxy(configService.get<string>('liquiLoans.baseUrl'), {
      https: true,
      memoizeHost: false,
      limit: 10 * 1024 * 1024,
      proxyReqOptDecorator: (proxyReqOpts, _srcReq) => {
        proxyReqOpts.headers['content-type'] = 'multipart/form-data';
        return proxyReqOpts;
      },
      proxyReqBodyDecorator: proxyMiddleware.bodyDecorator.bind(
        proxyMiddleware,
      ),
      proxyErrorHandler: proxyMiddleware.proxyErrorHandler.bind(
        proxyMiddleware,
      ),
      userResDecorator: proxyMiddleware.responseDecorator.bind(
        proxyMiddleware,
      ),
      proxyReqPathResolver: proxyMiddleware.pathResolver.bind(
        proxyMiddleware,
      ),
      reqAsBuffer: false,
    }),
  );;
monkpow commented 1 year ago

Thanks for the question. I'm looking into this.

monkpow commented 1 year ago

This appear to me to work as expected (at least in the test suite). Can you give more information about what you see when this is not working?

https://github.com/villadora/express-http-proxy/pull/527

monkpow commented 1 month ago

Hello @harsh-niyo. I'm closing this as it appears to be working as expected, and I haven't gotten any clarifying details from you. Feel free to re-open if you want to continue the discussion.