}
}
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
AuditLogEntry logEntry = getLogEntry(ctx);
Object message = e.getMessage();
if (message instanceof HttpResponse) {
HttpResponse response = (HttpResponse) message;
logEntry.setResponseCode(response.getStatus().getCode());
if (response.containsHeader(HttpHeaders.Names.CONTENT_LENGTH)) {
String lengthString = response.getHeader(HttpHeaders.Names.CONTENT_LENGTH);
try {
logEntry.setResponseContentLength(Long.valueOf(lengthString));
} catch (NumberFormatException nfe) {
LOG.warn("Invalid value for content length in HTTP response message: {}", lengthString, nfe);
}
}
} else if (message instanceof ChannelBuffer) {
// for chunked responses the response code will only be present on the first chunk
// so we only look for it the first time around
if (logEntry.getResponseCode() == null) {
ChannelBuffer channelBuffer = (ChannelBuffer) message;
logEntry.setResponseCode(findResponseCode(channelBuffer));
if (logEntry.getResponseCode() != null) {
// we currently only look for a Content-Length header in the first buffer on an HTTP response
// this is a limitation of the implementation that simplifies header parsing
logEntry.setResponseContentLength(findContentLength(channelBuffer));
}
}
} else {
LOG.debug("Unhandled response message type: {}", message.getClass());
}