From a99ab04fe5bccdd943c8eba892a9c30275689cea Mon Sep 17 00:00:00 2001 From: gregw Date: Wed, 11 Nov 2020 23:05:06 +0100 Subject: [PATCH] Cleanup request/response recycle #4711 Reordered recycle in request and response to field order so that we can check that all fields are recycled. --- .../org/eclipse/jetty/server/Request.java | 91 +++++++++---------- .../org/eclipse/jetty/server/Response.java | 9 +- 2 files changed, 50 insertions(+), 50 deletions(-) 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 b4d3b3d3ad88..85839e5e55fe 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 @@ -194,8 +194,8 @@ public static Request getBaseRequest(ServletRequest request) private String _contextPath; private String _servletPath; private String _pathInfo; - private boolean _secure; private Object _asyncNotSupportedSource = null; + private boolean _secure; private boolean _newContext; private boolean _cookiesExtracted = false; private boolean _handled = false; @@ -210,12 +210,12 @@ public static Request getBaseRequest(ServletRequest request) private CookieCutter _cookies; private DispatcherType _dispatcherType; private int _inputState = INPUT_NONE; + private BufferedReader _reader; + private String _readerEncoding; private MultiMap _queryParameters; private MultiMap _contentParameters; private MultiMap _parameters; private String _queryEncoding; - private BufferedReader _reader; - private String _readerEncoding; private InetSocketAddress _remote; private String _requestedSessionId; private UserIdentity.Scope _scope; @@ -1857,74 +1857,71 @@ public boolean hasMetaData() protected void recycle() { + getHttpChannelState().recycle(); + _requestAttributeListeners.clear(); + _input.recycle(); + _metaData = null; _originalURI = null; - + _contextPath = null; + _servletPath = null; + _pathInfo = null; + _asyncNotSupportedSource = null; + _secure = false; + _newContext = false; + _cookiesExtracted = false; + _handled = false; + _contentParamsExtracted = false; + _requestedSessionIdFromCookie = false; + _attributes = Attributes.unwrap(_attributes); + if (_attributes != null) + { + if (ServletAttributes.class.equals(_attributes.getClass())) + _attributes.clearAttributes(); + else + _attributes = null; + } + setAuthentication(Authentication.NOT_CHECKED); + _contentType = null; + _characterEncoding = null; if (_context != null) throw new IllegalStateException("Request in context!"); - - if (_inputState == INPUT_READER) + _context = null; + _errorContext = null; + if (_cookies != null) + _cookies.reset(); + _dispatcherType = null; + if (_reader != null) { try { int r = _reader.read(); while (r != -1) - { r = _reader.read(); - } } catch (Exception e) { LOG.ignore(e); _reader = null; + _readerEncoding = null; } } - - _dispatcherType = null; - setAuthentication(Authentication.NOT_CHECKED); - getHttpChannelState().recycle(); - if (_async != null) - _async.reset(); - _async = null; - _asyncNotSupportedSource = null; - _handled = false; - _attributes = Attributes.unwrap(_attributes); - if (_attributes != null) - { - if (ServletAttributes.class.equals(_attributes.getClass())) - _attributes.clearAttributes(); - else - _attributes = null; - } - _contentType = null; - _characterEncoding = null; - _contextPath = null; - if (_cookies != null) - _cookies.reset(); - _cookiesExtracted = false; - _context = null; - _errorContext = null; - _newContext = false; - _pathInfo = null; + _inputState = INPUT_NONE; + _queryParameters = null; + _contentParameters = null; + _parameters = null; _queryEncoding = null; + _remote = null; _requestedSessionId = null; - _requestedSessionIdFromCookie = false; - _secure = false; + _scope = null; _session = null; _sessionHandler = null; - _scope = null; - _servletPath = null; _timeStamp = 0; - _queryParameters = null; - _contentParameters = null; - _parameters = null; - _contentParamsExtracted = false; - _inputState = INPUT_NONE; _multiParts = null; - _remote = null; + if (_async != null) + _async.reset(); + _async = null; _sessions = null; - _input.recycle(); - _requestAttributeListeners.clear(); } /* diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java index 7d82d5318097..fb9cb07cd982 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java @@ -123,17 +123,20 @@ public HttpChannel getHttpChannel() protected void recycle() { + // _channel need not be recycled + _fields.clear(); + _errorSentAndIncludes.set(0); + _out.recycle(); _status = HttpStatus.OK_200; _reason = null; _locale = null; _mimeType = null; _characterEncoding = null; + _encodingFrom = EncodingFrom.NOT_SET; _contentType = null; _outputType = OutputType.NONE; + // _writer does not need to be recycled _contentLength = -1; - _out.recycle(); - _fields.clear(); - _encodingFrom = EncodingFrom.NOT_SET; _trailers = null; }