remm 02/03/14 21:45:05 Modified: http11/src/java/org/apache/coyote/http11 Http11Processor.java Log: - Add commons-logging based logger (static placeholder field at the moment; still better than writing directly to sys.err obviously). - Remove lots of the debug stack traces. - Add support for HTTP/1.1 expectations. - Add support for full HTTP/1.1 style URIs. When a full URI is used, the host header is optional. AFAIK, this was the last major feature missing in the processor. Revision Changes Path 1.9 +91 -30 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java Index: Http11Processor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Http11Processor.java 14 Mar 2002 21:45:05 -0000 1.8 +++ Http11Processor.java 15 Mar 2002 05:45:05 -0000 1.9 @@ -151,6 +151,12 @@ /** + * State flag. + */ + protected boolean started = false; + + + /** * Error flag. */ protected boolean error = false; @@ -187,6 +193,13 @@ protected String[] restrictedUserAgents = null; + /** + * Logger. + */ + protected static org.apache.commons.logging.Log log + = org.apache.commons.logging.LogFactory.getLog(Http11Processor.class); + + // --------------------------------------------------------- Public Methods @@ -267,10 +280,8 @@ // Error flag error = false; keepAlive = true; - // TEMP - boolean stopped = false; - while (!stopped && !error && keepAlive) { + while (started && !error && keepAlive) { try { inputBuffer.parseRequestLine(); @@ -279,8 +290,9 @@ error = true; break; } catch (Exception e) { - e.printStackTrace(); - //SC_BAD_REQUEST + log.warn("Error parsing HTTP request", e); + // 500 - Bad Request + response.setStatus(400); error = true; } @@ -288,14 +300,17 @@ prepareRequest(); // Process the request in the adapter - try { - adapter.service(request, response); - } catch (InterruptedIOException e) { - error = true; - } catch (Throwable t) { - // ISE - t.printStackTrace(); - error = true; + if (!error) { + try { + adapter.service(request, response); + } catch (InterruptedIOException e) { + error = true; + } catch (Throwable t) { + log.error("Error processing request", t); + // 500 - Internal Server Error + response.setStatus(500); + error = true; + } } // Finish the handling of the request @@ -304,8 +319,9 @@ } catch (IOException e) { error = true; } catch (Throwable t) { - // Problem ... - t.printStackTrace(); + log.error("Error finishing request", t); + // 500 - Internal Server Error + response.setStatus(500); error = true; } try { @@ -313,8 +329,7 @@ } catch (IOException e) { error = true; } catch (Throwable t) { - // Problem ... - t.printStackTrace(); + log.error("Error finishing response", t); error = true; } @@ -351,8 +366,7 @@ try { outputBuffer.commit(); } catch (IOException e) { - // Log the error, and set error flag - e.printStackTrace(); + // Set error flag error = true; } @@ -363,12 +377,19 @@ // Send a 100 status back if it makes sense (response not committed // yet, and client specified an expectation for 100-continue) - try { - outputBuffer.sendAck(); - } catch (IOException e) { - // Log the error, and set error flag - e.printStackTrace(); - error = true; + if (response.isCommitted()) + return; + + MessageBytes expectMB = + request.getMimeHeaders().getValue("expect"); + if ((expectMB != null) + && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) { + try { + outputBuffer.sendAck(); + } catch (IOException e) { + // Set error flag + error = true; + } } } else if (actionCode == ActionCode.ACTION_CLOSE) { @@ -381,8 +402,7 @@ try { outputBuffer.endRequest(); } catch (IOException e) { - // Log the error, and set error flag - e.printStackTrace(); + // Set error flag error = true; } @@ -398,6 +418,14 @@ // Do nothing + } else if (actionCode == ActionCode.ACTION_START) { + + started = true; + + } else if (actionCode == ActionCode.ACTION_STOP) { + + started = false; + } } @@ -488,14 +516,47 @@ } } + // Check for a full URI (including protocol://host:port/) + ByteChunk uriBC = request.requestURI().getByteChunk(); + if (uriBC.startsWithIgnoreCase("http", 0)) { + + // If the first character of the URI is 'h', the URI is either + // invalid, or is a full URI + + int pos = uriBC.indexOf("://", 0, 3, 4); + int uriBCStart = uriBC.getStart(); + int slashPos = -1; + if (pos != -1) { + byte[] uriB = uriBC.getBytes(); + slashPos = uriBC.indexOf('/', pos + 3); + if (slashPos == -1) { + slashPos = uriBC.getLength(); + // Set URI as "/" + request.requestURI().setBytes + (uriB, uriBCStart + pos + 1, 1); + } else { + request.requestURI().setBytes + (uriB, uriBCStart + slashPos, + uriBC.getLength() - slashPos); + } + MessageBytes hostMB = + request.getMimeHeaders().setValue("host"); + hostMB.setBytes(uriB, uriBCStart + pos + 3, + slashPos - pos - 3); + } + + } + // URI decoding try { request.decodedURI().duplicate(request.requestURI()); request.getURLDecoder().convert(request.decodedURI(), true); request.decodedURI().setEncoding("UTF-8"); } catch (IOException e) { - // URL decoding failed - e.printStackTrace(); + // 500 - Internal Server Error + response.setStatus(500); + log.warn("Error decoding URI"); + error = true; } // Input filter setup @@ -545,7 +606,7 @@ // Check host header if (http11 && (request.getMimeHeaders().getValue("host") == null)) { error = true; - // Send 400: Bad request + // 400 - Bad request response.setStatus(400); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>