From: <php...@li...> - 2010-08-05 21:33:54
|
hi, *Problem* I noticed a difference the $_SERVER['REQUEST_URI'] in PHP between a native php environment and in Java Bridge. In my test, I have a /test/index.php with the following line: <?php echo $_SERVER['REQUEST_URI']?> When I run Java bridge in Jetty, and used index.php as a welcome file in web.xml, when I hit /test/, the REQUEST_URI is /test/index.php, i.e. included the index file name. But when run in Nginx, and used index.php as an index file, for an identical request to /test/, the REQUEST_URI is /test/, i.e. without the index file name. This difference in behavior caused a trouble when running Wordpress as it is too intelligent to try to redirect a link with /index.php to /, but after the redirection, the servlet-Java-Bridge environment tell the PHP the new request is from /index.php again and result as a dead loop. Other than the modifying wordpress' source code to disable its "canonical detection", I thought about a workaround to map the PHP CGI servlet to "/" (or /* or whatever without .php at the end). It doesn't work and even if it works, it will also map all static files like images or javascript files (and favicon.ico!) to PHP. *Solution* Traced the code, I notice JavaBridge is using the following code to obtain the request_uri in FastCGIServlet.java: env.requestUri = (String) req.getAttribute("javax.servlet.include.request_uri"); if (env.requestUri == null) env.requestUri = req.getRequestURI(); In my Jetty environment, req.getAttribute("javax.servlet.include.request_uri") returns null, however, req.getAttribute("javax.servlet.forward.request_uri") will return the correct uri before forwarding. (i.e. "/test/" instead of "/test/index.php") Both javax.servlet.include.request_uri and javax.servlet.forward.request_uri are defined in the Servlet spec. For include, in Servlet spec 8.3.1, it is stated that: > javax.servlet.include.request_uri > ... > These attributes are accessible from the included servlet via the > getAttribute method on the request object and their values must be equal to > the request URI, context path, servlet path, path info, and query string of > the included servlet, respectively. If the request is subsequently included, > these attributes are replaced for that include. > For forward, in Servlet spec 8.4.2, it is stated that: > javax.servlet.forward.request_uri > ... > The values of these attributes must be equal to the return values of the > HttpServletRequest methods getRequestURI, getContextPath, getServletPath, > getPathInfo, getQueryString respectively, invoked on the request object > passed to the *first servlet object* in the call chain that received the > request from the client. > I'm not sure which one is supposed to be correct but the javax.servlet.forward.request_uri attribute is said to be the request uri of the first servlet object of a chain, that won't be modified by subsequent servlet, and it gives a correct value in my test. could JavaBridge make a change either to use the forward.request_uri or just check both attributes? should i make a patch? regards, mingfai |