Author: markt Date: Thu Dec 29 06:06:58 2005 New Revision: 359798 URL: http://svn.apache.org/viewcvs?rev=359798&view=rev Log: Fix for bug 38012. Allow CGI scripts to issue redirects. Actually a more general fix that allows CGI to set response status.
Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java tomcat/container/tc5.5.x/webapps/docs/changelog.xml Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java?rev=359798&r1=359797&r2=359798&view=diff ============================================================================== --- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java (original) +++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java Thu Dec 29 06:06:58 2005 @@ -1772,10 +1772,7 @@ log("runCGI: addHeader(\"" + line + "\")"); } if (line.startsWith("HTTP")) { - //TODO: should set status codes (NPH support) - /* - * response.setStatus(getStatusCode(line)); - */ + response.setStatus(getStatus(line)); } else if (line.indexOf(":") >= 0) { String header = line.substring(0, line.indexOf(":")).trim(); @@ -1851,6 +1848,36 @@ } } + /** + * Parses the status header and extracts the status code. + * + * @param line The HTTP Status-Line (RFC2616, section 6.1) + * @return The extracted status code or the code representing an + * internal error if a valid status code cannot be extracted. + */ + private int getStatus(String line) { + int statusStart = line.indexOf(' '); + + if (statusStart < 0 || line.length() < statusStart + 4) { + // Not a valid status line + log ("runCGI: invalid status line:" + line); + return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; + } + + String status = line.substring(statusStart + 1, statusStart + 4); + + int statusCode; + try { + statusCode = Integer.parseInt(status); + } catch (NumberFormatException nfe) { + // Not a valid status code + log ("runCGI: invalid status code:" + status); + return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; + } + + return statusCode; + } + private void sendToLog(BufferedReader rdr) { String line = null; int lineCount = 0 ; Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?rev=359798&r1=359797&r2=359798&view=diff ============================================================================== --- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original) +++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Thu Dec 29 06:06:58 2005 @@ -34,6 +34,9 @@ Remove leftover static logger which was used to log application level messages in ApplicationContextFacade (remm) </fix> + <fix> + <bug>38012</bug>: Where a CGI script sets a response code, use it. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]