Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure access log always logs the correct remote IP.
Ensure requests with multiple errors do not result in multiple access log entries. 

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk@1176592 13f79535-47bb-0310-9956-ffa450edef68
markt-asf committed Sep 27, 2011
1 parent d5bd2e6 commit 9eae334
Showing 7 changed files with 18 additions and 19 deletions.
6 changes: 1 addition & 5 deletions java/org/apache/catalina/connector/CoyoteAdapter.java
Original file line number Diff line number Diff line change
@@ -466,10 +466,8 @@ public void log(org.apache.coyote.Request req,

Request request = (Request) req.getNote(ADAPTER_NOTES);
Response response = (Response) res.getNote(ADAPTER_NOTES);
boolean create = false;

if (request == null) {
create = true;
// Create objects
request = connector.createRequest();
request.setCoyoteRequest(req);
@@ -511,9 +509,7 @@ public void log(org.apache.coyote.Request req,
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log.warn(sm.getString("coyoteAdapter.accesslogFail"), t);
}

if (create) {
} finally {
request.recycle();
response.recycle();
}
7 changes: 3 additions & 4 deletions java/org/apache/coyote/ajp/AbstractAjpProcessor.java
Original file line number Diff line number Diff line change
@@ -759,7 +759,6 @@ protected void prepareRequest() {
secret = true;
if (!tmpMB.equals(requiredSecret)) {
response.setStatus(403);
adapter.log(request, response, 0);
error = true;
}
}
@@ -776,7 +775,6 @@ protected void prepareRequest() {
// Check if secret was submitted if required
if ((requiredSecret != null) && !secret) {
response.setStatus(403);
adapter.log(request, response, 0);
error = true;
}

@@ -810,6 +808,9 @@ protected void prepareRequest() {
MessageBytes valueMB = request.getMimeHeaders().getValue("host");
parseHost(valueMB);

if (error) {
adapter.log(request, response, 0);
}
}


@@ -825,7 +826,6 @@ protected void parseHost(MessageBytes valueMB) {
request.serverName().duplicate(request.localName());
} catch (IOException e) {
response.setStatus(400);
adapter.log(request, response, 0);
error = true;
}
return;
@@ -877,7 +877,6 @@ protected void parseHost(MessageBytes valueMB) {
error = true;
// 400 - Bad request
response.setStatus(400);
adapter.log(request, response, 0);
break;
}
port = port + (charValue * mult);
2 changes: 1 addition & 1 deletion java/org/apache/coyote/ajp/AjpAprProcessor.java
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ public SocketState process(SocketWrapper<Long> socket)
}
}

if (!cping && endpoint.isPaused()) {
if (!error && !cping && endpoint.isPaused()) {
// 503 - Service unavailable
response.setStatus(503);
adapter.log(request, response, 0);
2 changes: 1 addition & 1 deletion java/org/apache/coyote/ajp/AjpNioProcessor.java
Original file line number Diff line number Diff line change
@@ -169,7 +169,7 @@ public SocketState process(SocketWrapper<NioChannel> socket)
}
}

if (!cping && endpoint.isPaused()) {
if (!error && !cping && endpoint.isPaused()) {
// 503 - Service unavailable
response.setStatus(503);
adapter.log(request, response, 0);
2 changes: 1 addition & 1 deletion java/org/apache/coyote/ajp/AjpProcessor.java
Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ public SocketState process(SocketWrapper<Socket> socket)
}
}

if (!cping && endpoint.isPaused()) {
if (!error && !cping && endpoint.isPaused()) {
// 503 - Service unavailable
response.setStatus(503);
adapter.log(request, response, 0);
13 changes: 6 additions & 7 deletions java/org/apache/coyote/http11/AbstractHttp11Processor.java
Original file line number Diff line number Diff line change
@@ -897,7 +897,6 @@ public SocketState process(SocketWrapper<S> socketWrapper)
if (endpoint.isPaused()) {
// 503 - Service unavailable
response.setStatus(503);
adapter.log(request, response, 0);
error = true;
} else {
request.setStartTime(System.currentTimeMillis());
@@ -1087,7 +1086,6 @@ protected void prepareRequest() {
" Unsupported HTTP version \""+protocolMB+"\"");
}
response.setStatus(505);
adapter.log(request, response, 0);
}

MessageBytes methodMB = request.method();
@@ -1183,7 +1181,6 @@ protected void prepareRequest() {
error = true;
// 501 - Unimplemented
response.setStatus(501);
adapter.log(request, response, 0);
}
startPos = commaPos + 1;
commaPos = transferEncodingValue.indexOf(',', startPos);
@@ -1199,7 +1196,6 @@ protected void prepareRequest() {
" Unsupported transfer encoding \""+encodingName+"\"");
}
response.setStatus(501);
adapter.log(request, response, 0);
}
}

@@ -1222,7 +1218,6 @@ protected void prepareRequest() {
" host header missing");
}
response.setStatus(400);
adapter.log(request, response, 0);
}

parseHost(valueMB);
@@ -1252,6 +1247,10 @@ protected void prepareRequest() {
request.setAttribute("org.apache.tomcat.comet.timeout.support",
Boolean.TRUE);
}

if (error) {
adapter.log(request, response, 0);
}
}


@@ -1471,7 +1470,6 @@ protected void parseHost(MessageBytes valueMB) {
error = true;
// 400 - Bad request
response.setStatus(400);
adapter.log(request, response, 0);
break;
}
port = port + (charValue * mult);
@@ -1552,8 +1550,9 @@ public void endRequest() {
ExceptionUtils.handleThrowable(t);
getLog().error(sm.getString("http11processor.request.finish"), t);
// 500 - Internal Server Error
// Can't add a 500 to the access log since that has already been
// written in the Adapter.service method.
response.setStatus(500);
adapter.log(request, response, 0);
error = true;
}
try {
5 changes: 5 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
@@ -133,6 +133,11 @@
Ensure Servlets that implement ContainerServlet always get treated as
restricted. (markt)
</fix>
<fix>
Ensure that the access log always uses the correct value for the remote
IP address associated with the request and that requests with multiple
errors do not result in multiple entires in the access log. (markt)
</fix>
</changelog>
</subsection>
<subsection name="Coyote">

0 comments on commit 9eae334

Please sign in to comment.