chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.79k stars 852 forks source link

FIX: response-interceptor.ts #1057

Open kogovsekmatic opened 2 weeks ago

kogovsekmatic commented 2 weeks ago

Checks

Describe the bug (be clear and concise)

function copyHeaders: RegEx for Domain=*; matches only the first character not the whole domain for example Domain=example.com; replaces strips Domain=e but leaves xample.com

Step-by-step reproduction instructions

Using the request interceptor

Expected behavior (be clear and concise)

to strip the entire Domain=*;

How is http-proxy-middleware used in your project?

Proxying things

What http-proxy-middleware configuration are you using?

export const proxyConfig = createProxyMiddleware({
  target,
  changeOrigin: false,
  selfHandleResponse: true,
  on: {
    proxyRes: responseInterceptor(
      async (responseBuffer, proxyRes, req, res) => {
        let response = responseBuffer.toString("utf8");
        // Return
        return response;
      }
    ),
  },
});

What OS/version and node/version are you seeing the problem?

MacOS

Additional context (optional)

keys.forEach((key) => {
  let value = originalResponse.headers[key];
  if (key === "set-cookie") {
    // remove cookie domain
    value = Array.isArray(value) ? value : [value];
    value = value
      .map((x) => x.replace(/Domain=[^;]+;?/i, "")
      .replace(/\s+/g, " "));
  }
  response.setHeader(key, value);
});