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

url matching doesnt take into account the URL encoding #35

Open
jepetko opened this issue Sep 4, 2013 · 0 comments
Open

url matching doesnt take into account the URL encoding #35

jepetko opened this issue Sep 4, 2013 · 0 comments

Comments

@jepetko
Copy link

jepetko commented Sep 4, 2013

I had to create a reverse proxy for encoded_uri in this URL:

/proxy?url=encoded_uri

The configuration of the proxy:

  reverse_proxy /^\/proxy\?url=(.*)$/, "$1", :preserve_host => false

The problem is that the implementation of get_uri doesnt take into account the URL encoding of the parameter and it returns:

https%3A%2F%2Fgithub.com%2Fjaswope%2Frack-reverse-proxy%2Fissues%2Fnew

which causes an internal server error.

My fix:

class Rack::ReverseProxyMatcher

  alias_method :get_uri_without_decode, :get_uri

  def get_uri(path,env)
    puts 'this is a monkeypatched method for :get_uri'
    url = get_uri_without_decode(path,env)
    if url.path.start_with?('http%')
      url = URI.decode url.path
      url = URI(url)
    end
    url
  end
end
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

1 participant