From: <php...@li...> - 2010-08-12 10:59:59
|
> > Jetty behaves correctly. > > I don't follow. Doesn't jetty return null for getRequestURI()? > > sorry, maybe i didn't make it clear enough. Jetty does *not* return null for getRequestURI(). it "correctly" return "/index.php". There is no bug involved. I am using the latest Jetty 7.1.6 and it behaves exactly as I expected. Jetty may have bugs, maybe very buggy (if you guys think so, I don't really so ;-) ), but this issue doesn't caused by any Jetty bug. as you guys keep thinking it is a Jetty bug, I've checked the servlet spec by myself. the servlet spec 2.5 doesn't disallow explicit forwarding for welcome-file. In servlet spec 2.5 section 9.1, when a welcome file is defined, it only say "A request URI of /catalog/ will be returned as /catalog/default.jsp.". It used the term "returned" but not forwarded nor redirected. From the context, you actually may interpret "return" as "forward" because for the other case, the spec used the term "redirect".And the spec definitely didn't require getRequestURI to return the request uri of the first request. otherwise, it won't need the javax.servlet.forward.* attributes. the behavior of tomcat and jetty are different in welcome file implementation. Jetty actually explicitly do a forwarding, but tomcat doesn't do any forwarding (or it does the forwarding transparent). > > > <!-- from.jsp --> > > <jsp:forward page="to.php"/> > ... > > Now, come back to the question of whether Java Bridge should take the > source > > or the target? it seems to me Java Bridge should always take the source > as > > it is server side forwarding but not http redirect. > > How do you expect PHP to evaluate "from.jsp"? It should eval "to.php". > > Let's assume user type "http://acme.com/from.jsp". And in the jsp, it forwards to "/to.php". I do expect the REQUEST_URI variable in PHP shows "/from.jsp" which is the uri that the user requested. why?! this is a good question. the best reason i can give is "REQUEST_URI should return the URI that user requested" :-) - by fact, it won't work if REQUEST_URI isn't the original request uri in wordpress. As wordpress will do redirection if the uri is not correct. let's ignore wordpress first. it is popular but just one php applications. - in a normal web server like Apache or Nginx, if you view index file as a kind of servlet side forwarding, a request to "/test/" that is forwarded to "/test/index.php" will show "/test/" as the REQUEST_URI. "/test/" is the source, but not the forwarded target. - if you REQUEST_URI doesn't return the source, there is no way to obtain the source/original request uri. In PHP, we can use $_SERVER["SCRIPT_NAME"] to get the current file, which is the target. There is no need to make REQUEST_URI returns the same target. - i'm not a php expert. afaik, php doesn't have a server side forward feature, so there is no absolute expected behavior. it seems to me the definition of REQUEST_URI is a grey area so don't worry if our views are different. > > There is no problem in Tomcat because when we make a request to "/", it > > transparently take the index file "/index.php" but getRequestURI() > remains > > at "/". > > In tomcat targetServlet.getRequestURI() returns "/index.php", as it should > be. > > i did a test before writing my last email, and i just repeated the test to double check. In Tomcat 6.0.29, when the web app is configured with: <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> when we hit a URI without "index.jsp" suffix, e.g. "/test/", when there is actually a "/test/index.jsp" with the following content: <%=request.getRequestURI() %><br/> <%=request.getAttribute("javax.servlet.include.request_uri") %><br/> <%=request.getAttribute("javax.servlet.forward.request_uri") %><br/> it will print out: /test/ null null You could do a quick test with my attached test.war. The behavior of Tomcat is stated as a reference only. It got nothing to do with the issue I'm reporting. > > > For this scenario, JavaBridge should not use the to.php as REQUEST_URI, > but > > should use the from. > > If you know how to distinguish "this scenario", we can add a > workaround for this jetty bug. Your current patch breaks code like > <jsp:forward page="some.php">, so I will not apply it. > I think the issue is not a workaround, and as mentioned, Jetty behaves correctly. The issue is our difference in the expected behavior of a jsp forward case. I think the REQUEST_URI should return the source but not the target, and you think differently. btw, Tomcat doesn't implemenet javax.servlet.* attributes at all so the patch won't affect it. I Even thought I want to fix "this scenario", i wouldn't suggest to detect if it is jetty and then sth differently for Jetty. right now, i've patched my local version. Not the best but acceptable to me. And I think FastCGIServlet is designed to be extendable so anyone could override the setupRequestVariables method. If you don't REQUEST_URI should return the source, just ignore this issue. Don't worry. regards, mingfai |