You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2005/12/29 15:04:51 UTC
svn commit: r359797 -
/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java
Author: markt
Date: Thu Dec 29 06:04:47 2005
New Revision: 359797
URL: http://svn.apache.org/viewcvs?rev=359797&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. Ported from TC5.
Modified:
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java
Modified: tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java
URL: http://svn.apache.org/viewcvs/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java?rev=359797&r1=359796&r2=359797&view=diff
==============================================================================
--- tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java (original)
+++ tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java Thu Dec 29 06:04:47 2005
@@ -246,9 +246,6 @@
/* some vars below copied from Craig R. McClanahan's InvokerServlet */
- /** the Context container associated with our web application. */
- private ServletContext context = null;
-
/** the debugging detail level for this servlet. */
private int debug = 0;
@@ -318,6 +315,7 @@
} catch (IOException ioe) {
ServletException e = new ServletException(
"Unable to read shell environment variables", ioe);
+ throw e;
}
}
@@ -326,9 +324,6 @@
cgiExecutable = value;
}
- // Identify the internal container resources we need
- context = config.getServletContext();
-
}
@@ -1424,6 +1419,10 @@
* @version $Revision$, $Date$
*/
+ /**
+ * @author Mark
+ *
+ */
protected class CGIRunner {
/** script/command to be executed */
@@ -1771,10 +1770,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();
@@ -1841,6 +1837,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 ;
@@ -1873,7 +1899,6 @@
*/
protected String getPostInput(ArrayList params) {
- String lineSeparator = System.getProperty("line.separator");
StringBuffer qs = new StringBuffer("");
for (int i=0; i < params.size(); i++) {
NameValuePair nvp = (NameValuePair) this.params.get(i);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org