From 0bc9149ff1d0200410a7208863d5e31e24784bba Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 17 Jul 2017 11:37:03 +0200 Subject: [PATCH] Issue #1671 asymmetric trailer usage on MetaData.Request --- .../java/org/eclipse/jetty/server/HttpChannel.java | 13 ++++++++++++- .../main/java/org/eclipse/jetty/server/Request.java | 13 +++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 5a929d57cef..251082166e8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Supplier; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -75,9 +76,18 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor private final HttpChannelState _state; private final Request _request; private final Response _response; + private final Supplier _trailerSupplier = new Supplier() + { + @Override + public HttpFields get() + { + return _trailers; + } + }; private MetaData.Response _committedMetaData; private RequestLog _requestLog; private long _oldIdleTimeout; + private HttpFields _trailers; /** Bytes written after interception (eg after compression) */ private long _written; @@ -581,6 +591,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor if (idleTO>=0 && _oldIdleTimeout!=idleTO) setIdleTimeout(idleTO); + request.setTrailerSupplier(_trailerSupplier); _request.setMetaData(request); if (LOG.isDebugEnabled()) @@ -608,7 +619,7 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor { if (LOG.isDebugEnabled()) LOG.debug("{} onTrailers {}", this, trailers); - _request.setTrailers(trailers); + _trailers = trailers; } public boolean onRequestComplete() diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index d84f7e5713e..0a7f16b7c40 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -39,6 +39,7 @@ import java.util.EventListener; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.function.Supplier; import java.util.stream.Collectors; import javax.servlet.AsyncContext; @@ -199,7 +200,6 @@ public class Request implements HttpServletRequest private long _timeStamp; private MultiPartInputStreamParser _multiPartInputStream; //if the request is a multi-part mime private AsyncContextState _async; - private HttpFields _trailers; /* ------------------------------------------------------------ */ public Request(HttpChannel channel, HttpInput input) @@ -215,9 +215,12 @@ public class Request implements HttpServletRequest return metadata==null?null:metadata.getFields(); } + /* ------------------------------------------------------------ */ public HttpFields getTrailers() { - return _trailers; + MetaData.Request metadata=_metaData; + Supplier trailers = metadata==null?null:metadata.getTrailerSupplier(); + return trailers==null?null:trailers.get(); } /* ------------------------------------------------------------ */ @@ -1859,7 +1862,6 @@ public class Request implements HttpServletRequest _multiPartInputStream = null; _remote=null; _input.recycle(); - _trailers = null; } /* ------------------------------------------------------------ */ @@ -2228,11 +2230,6 @@ public class Request implements HttpServletRequest _scope = scope; } - public void setTrailers(HttpFields trailers) - { - _trailers = trailers; - } - /* ------------------------------------------------------------ */ @Override public AsyncContext startAsync() throws IllegalStateException