Reset trailers on recycled response
Whilst investigating #4711 for jetty-10, it was noticed that trailers are not nulled on recycled Response instances, nor on reset. Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
e913ed233a
commit
f4da9760fd
|
@ -132,6 +132,7 @@ public class Response implements HttpServletResponse
|
||||||
_out.recycle();
|
_out.recycle();
|
||||||
_fields.clear();
|
_fields.clear();
|
||||||
_encodingFrom = EncodingFrom.NOT_SET;
|
_encodingFrom = EncodingFrom.NOT_SET;
|
||||||
|
_trailers = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpOutput getHttpOutput()
|
public HttpOutput getHttpOutput()
|
||||||
|
@ -1080,6 +1081,7 @@ public class Response implements HttpServletResponse
|
||||||
_mimeType = null;
|
_mimeType = null;
|
||||||
_characterEncoding = null;
|
_characterEncoding = null;
|
||||||
_encodingFrom = EncodingFrom.NOT_SET;
|
_encodingFrom = EncodingFrom.NOT_SET;
|
||||||
|
_trailers = null;
|
||||||
|
|
||||||
// Clear all response headers
|
// Clear all response headers
|
||||||
_fields.clear();
|
_fields.clear();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -165,6 +166,7 @@ public class HttpTrailersTest extends AbstractTest<TransportScenario>
|
||||||
|
|
||||||
private void testResponseTrailers(byte[] content) throws Exception
|
private void testResponseTrailers(byte[] content) throws Exception
|
||||||
{
|
{
|
||||||
|
final AtomicBoolean once = new AtomicBoolean(false);
|
||||||
String trailerName = "Trailer";
|
String trailerName = "Trailer";
|
||||||
String trailerValue = "value";
|
String trailerValue = "value";
|
||||||
scenario.start(new AbstractHandler()
|
scenario.start(new AbstractHandler()
|
||||||
|
@ -173,12 +175,15 @@ public class HttpTrailersTest extends AbstractTest<TransportScenario>
|
||||||
public void handle(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
|
public void handle(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||||
{
|
{
|
||||||
jettyRequest.setHandled(true);
|
jettyRequest.setHandled(true);
|
||||||
|
|
||||||
HttpFields trailers = new HttpFields();
|
|
||||||
trailers.put(trailerName, trailerValue);
|
|
||||||
|
|
||||||
Response jettyResponse = (Response)response;
|
Response jettyResponse = (Response)response;
|
||||||
jettyResponse.setTrailers(() -> trailers);
|
|
||||||
|
if (once.compareAndSet(false, true))
|
||||||
|
{
|
||||||
|
HttpFields trailers = new HttpFields();
|
||||||
|
trailers.put(trailerName, trailerValue);
|
||||||
|
jettyResponse.setTrailers(() -> trailers);
|
||||||
|
}
|
||||||
|
|
||||||
if (content != null)
|
if (content != null)
|
||||||
response.getOutputStream().write(content);
|
response.getOutputStream().write(content);
|
||||||
}
|
}
|
||||||
|
@ -205,6 +210,26 @@ public class HttpTrailersTest extends AbstractTest<TransportScenario>
|
||||||
.send();
|
.send();
|
||||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||||
assertNull(failure.get());
|
assertNull(failure.get());
|
||||||
|
|
||||||
|
// subsequent requests should not have trailers
|
||||||
|
response = scenario.client.newRequest(scenario.newURI())
|
||||||
|
.onResponseSuccess(r ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponse httpResponse = (HttpResponse)r;
|
||||||
|
assertNull(httpResponse.getTrailers());
|
||||||
|
failure.set(null);
|
||||||
|
}
|
||||||
|
catch (Throwable x)
|
||||||
|
{
|
||||||
|
failure.set(x);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.timeout(5, TimeUnit.SECONDS)
|
||||||
|
.send();
|
||||||
|
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||||
|
assertNull(failure.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
|
Loading…
Reference in New Issue