Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urlencoded does not work when using socks-proxy-agent #878

Open
2 tasks done
xTCry opened this issue Feb 17, 2023 · 1 comment
Open
2 tasks done

urlencoded does not work when using socks-proxy-agent #878

xTCry opened this issue Feb 17, 2023 · 1 comment

Comments

@xTCry
Copy link

xTCry commented Feb 17, 2023

Checks

Describe the bug (be clear and concise)

If a custom agent is specified in the configuration, for example, in my case, socks-proxy-agent, then the urlencode function cannot complete its work.

That is, no events for socket are called inside it.

The debug log body-parser:urlencoded has this output:

  body-parser:urlencoded content-type "application/x-www-form-urlencoded" +0ms
  body-parser:urlencoded content-encoding "identity" +2ms
  body-parser:urlencoded read body +1ms

Step-by-step reproduction instructions

1. Create a express server using createProxyMiddleware with configured agent socks-proxy-agent (socks5)
2. Run proxy app
3. Create a POST request

Expected behavior (be clear and concise)

It is expected that the urlencode function will give the result as without using a custom agent.
The debug log body-parser:urlencoded should contain this output:

  body-parser:urlencoded content-type "application/x-www-form-urlencoded" +0ms
  body-parser:urlencoded content-encoding "identity" +2ms
  body-parser:urlencoded read body +0ms
  body-parser:urlencoded parse body +11ms
  body-parser:urlencoded parse extended urlencoding +1ms

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

http-proxy-middleware@2.0.6
socks-proxy-agent@^7.0.0

What http-proxy-middleware configuration are you using?

import { SocksProxyAgent } from 'socks-proxy-agent';
const httpAgent = new SocksProxyAgent('socks5://...');

// createProxyMiddleware config:
  {
    target: xEnv.PROXY_TARGET,
    changeOrigin: true,
    toProxy: true,
    secure: false,
    // onProxyRes: this.onProxyRes.bind(this),
    onProxyReq: (proxyReq, req, res) => {
      if (req.method !== 'POST') return;
      urlencoded({ extended: false })(req, res, (err) => {
        console.log('REQ && ERR', req, err);
        !err && this.featuresService.logPostRequest(req as Request);
      });
    },
    onError(err, req, res) {
      const { code = '', message } = err as any;
      if (['ECONNRESET', 'ETIMEDOUT'].some((e) => code.includes(e) || message.includes(e))) {
        res.writeHead(503, { 'Content-Type': 'text/plain; charset=utf-8' });
        res.end('The server is currently unavailable. Try again later.');
        return;
      }

      res.writeHead(500, { 'Content-Type': 'text/plain; charset=utf-8' });
      res.end('Something went wrong.');
    },
    logLevel: 'debug',
    prependPath: false,
    agent: httpAgent,
  }

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

Windows 10 & Node: 16.19.0

Additional context (optional)

No response

@314171441
Copy link

me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants