Index: modules/util/src/main/java/org/mortbay/servlet/CGI.java =================================================================== --- modules/util/src/main/java/org/mortbay/servlet/CGI.java (revision 2030) +++ modules/util/src/main/java/org/mortbay/servlet/CGI.java (working copy) @@ -288,10 +288,11 @@ // NOTE: Multiline header items not supported! String line=null; InputStream inFromCgi=p.getInputStream(); + InputStream errFromCgi=p.getErrorStream(); //br=new BufferedReader(new InputStreamReader(inFromCgi)); //while ((line=br.readLine())!=null) - while( (line = getTextLineFromStream( inFromCgi )).length() > 0 ) + while( (line = getTextLineFromStream( inFromCgi, errFromCgi )).length() > 0 ) { if (!line.startsWith("HTTP")) { @@ -318,6 +319,7 @@ } } } + // copy cgi content to response stream... os = res.getOutputStream(); IO.copy(inFromCgi, os); @@ -360,14 +362,25 @@ * @return the line of text * @throws IOException */ - private String getTextLineFromStream( InputStream is ) throws IOException { + private String getTextLineFromStream( InputStream is, InputStream es ) throws IOException { StringBuffer buffer = new StringBuffer(); int b; - while( (b = is.read()) != -1 && b != (int) '\n' ) { - buffer.append( (char) b ); - } - return buffer.toString().trim(); + while (true) { + if (is.available() > 0) { + // Read a character + b = is.read(); + if (b == -1 || b == (int) '\n') { + return buffer.toString().trim(); + } + buffer.append( (char) b ); + } + if (es.available() > 0) { + // Read a character and ignore it + b = es.read(); + } + } + } /* ------------------------------------------------------------ */ /**