Some sites break because of req.url being absolute
Problem
According to the HTTP standard, a request's URI (the second field in the first line of an HTTP request, after the verb, and which gets into req.url) may be relative or absolute. A request to a proxy must always have an absolute URI, and indeed when we receive a request, req.url is always absolute. We just forward the request in proxyRequest and copy the URI into the new request. The receiving end of our new request will in turn get an absolute URI. This behaviour, however standard, is breaking some sites which naively expect the path to be relative to the hostname (starting with a "/"). They are wrong, but still node-http-proxy could be "fixed" so as to not break this assumption of theirs. By placing "req.url = req.url.replace(/._?:\/\/._?\//, '/')" (an ugly regexp, granted) before calling proxyRequest I was able to conform to the naiveté of Wordpress and other stuff which is out there being used and does not implement the standard. Thanks for building this nice, flexible proxy.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Some sites break because of req.url being absolute
Here is my changeset to my front-end dev tool using node-http-proxy which fixes this assumption. https://github.com/fabiosantoscode/magicProxy/commit/d8118e37532bc479e71a806b8f1e2fcc9d8763db
Trust Score
1 verification
- 1
Here is my changeset to my front-end dev tool using node-http-proxy which fixes
Here is my changeset to my front-end dev tool using node-http-proxy which fixes this assumption.
- 2
https://github.com/fabiosantoscode/magicProxy/commit/d8118e37532bc479e71a806b8f1
https://github.com/fabiosantoscode/magicProxy/commit/d8118e37532bc479e71a806b8f1e2fcc9d8763db
Validation
Resolved in http-party/node-http-proxy GitHub issue #529. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep