oracle / opengrok

OpenGrok is a fast and usable source code search and cross reference engine, written in Java
http://oracle.github.io/opengrok/
Other
4.34k stars 745 forks source link

goFirstProject does not add trailing slash #949

Open lllama opened 9 years ago

lllama commented 9 years ago

Double clicking on a project causes the request to be redirected to the version with the trailing slash. This can cause issues when behind a reverse proxy.

tarzanek commented 9 years ago

this should be fixed then, can you add a test steps to this bug? of course the fix will be probably easy, so patches are welcome

vladak commented 9 years ago

What version are you running ?

We've been running OpenGrok 0.12.1.5 in Tomcat 6 behind Apache 2.2 mod_proxy and the problem does not happen there.

lllama commented 9 years ago

This is the line where the redirect is built: https://github.com/OpenGrok/OpenGrok/blob/master/web/utils.js#L416

I'm running 0.12.1 under Tomcat 7 behind a node proxy that I'm writing (because of Reasons). It would appear that I was having two issues: I had initially configured the proxy to follow redirects, so I'd get the correct page but the user-agent didn't end up adding the trailing slash. Once I corrected that then it appears that OpenGrok is redirecting to its internal IP, rather than that of the proxy. I shall have a dig into the code and see what headers I should be adding.

vladak commented 9 years ago

That's known behavior. I did not find a way how to fix it properly since the URL scheme is not propagated through the proxy. See #890 for more info and workaround.

Of course, if you can find a better way that would be awesome.

vladak commented 9 years ago

Maybe we should use "X-Forwarded-Host" header (if present) to construct xrefPath somewhere in menu.jspf:

68<script type="text/javascript">/* <![CDATA[ */
69    document.projects = [ <%= Util.encode(jsProjects.toString())
70    %> ];document.xrefPath = '<%= request.getContextPath() + Prefix.XREF_P
71    %>';document.domReady.push(function() { domReadyMenu(); });
72/* ]]> */
73</script><%

just like it was done in 6640ccead338f3719e48a319ac742576d7fcb61c ?

lllama commented 9 years ago

I think the solution used to fix the RSS feed is the best compromise - using the X-Forwarded-Host header will prevent redirecting to internal hosts, and handling the schema should be left to the proxy itself (which one could argue should be the case anyway e.g. proxy being used to provide SSL).