dvonlehman / express-request-proxy

Advanced streaming http request proxy middleware for Express with support for custom routes, caching, and response transforms.
95 stars 38 forks source link

slashes in wildcard paths are being encoded on the outgoing request #8

Closed duanefields closed 8 years ago

duanefields commented 8 years ago

Given the request

http://localhost:3000/epiquery/glgCurrentUser/getUserByLogin.mustache

And the mapping

console.log "Using #{app.get 'episerver'} for Epiquery"
router.all '/*', proxy
  url: "#{app.get 'episerver'}/*"
  headers:
    Authorization: app.get 'epiauth'

Where the epiquery server var is http://localhost:8080

The proxy code is escaping the slashes in the path

http://localhost:9700/glgCurrentUser%2FgetUserByLogin.mustache

The problem seems to be in request-options.js, line 47 - compiledPath regexp is escaping the path

/glgCurrentUser%2FgetUserByLogin.mustache

I'm guessing the fault is in path-to-regexp, but that's as far as I've gotten.

duanefields commented 8 years ago

Wrapping line 47 in decodeURIComponent fixes it - but I'm not familiar enough with the rest of the code to know if this is a fix, or just hacking one particular case and breaking everything else....

    pathname: decodeURIComponent(compiledPath(_.extend({}, req.params, options.params))),
dvonlehman commented 8 years ago

That seems like a reasonable solution. I will make that change and add a unit test with your use case. Risk seems low that this would have any detrimental impacts on the happy path. You are also welcome to make a pull request with the change and a corresponding unit test if you like. Either way thanks for raising the issue.

duanefields commented 8 years ago

Never mind... this exact fix is already in 1.1.0 - I had a stale version of the package... I swear I'd checked that...