Skip to content

fix path-rewrite-bug #1129

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shaojieliu-xinye
Copy link

Fix Path Rewrite Issue with curl -x Proxy AND nginx check

Description

When using curl -x to send requests through a proxy, the path-rewrite functionality does not work as expected. This issue arises because the proxy server does not correctly handle the path rewriting rules specified in the request.

Motivation and Context

When sending a request through a proxy using curl -x, the path-rewrite rules defined in the request are not applied. This results in the request being sent to the target server with the original path, rather than the rewritten path.

How has this been tested?

configuration like this

let hsOptions = {
    target: 'http://127.0.0.1:9000/hs',
    changeOrigin: true,
    logLevel: 'debug',
    ws: false,
    pathRewrite: {
      '^/hs' : ''
    }
}
let hsProxy = proxy('/hs', hsOptions)
app.use(hsProxy);

then start the node with 80 port

curl -x http://127.0.0.1:80 http://test.domain.com/hs

In this example, the request should be rewritten to http://127.0.0.1:9000/hs, but instead, it is sent as http://127.0.0.1:9000/hs/hs.

solution

before path-rewrite, parse the full url, get the real path inestead of the url

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

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

Successfully merging this pull request may close these issues.

1 participant