From b04924d2b1e97062bfd7882f85a96e8989bc544e Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 11 Dec 2017 11:39:58 +0000 Subject: [PATCH] Jetty: Fix request log showing zero length for static content --- apps/jetty/java/src/net/i2p/jetty/I2PRequestLog.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/jetty/java/src/net/i2p/jetty/I2PRequestLog.java b/apps/jetty/java/src/net/i2p/jetty/I2PRequestLog.java index 83c82b591..32f01ddd1 100644 --- a/apps/jetty/java/src/net/i2p/jetty/I2PRequestLog.java +++ b/apps/jetty/java/src/net/i2p/jetty/I2PRequestLog.java @@ -331,6 +331,17 @@ public class I2PRequestLog extends AbstractLifeCycle implements RequestLog long responseLength=response.getContentCount(); + // The above is what Jetty used before 9, but now + // it often (for large content?) returns 0 for non-cgi responses. + // Now, Jetty uses getLongContentLength(), but according to + // these threads it returns 0 for streaming (cgi) responses. + // So we take whichever one is nonzero, if the result was 200. + // See: + // https://dev.eclipse.org/mhonarc/lists/jetty-dev/msg02261.html + // and followups including this workaround: + // https://dev.eclipse.org/mhonarc/lists/jetty-dev/msg02267.html + if (responseLength == 0 && status == 200 && !"HEAD".equals(request.getMethod())) + responseLength = response.getLongContentLength(); if (responseLength >=0) { buf.append(' ');