Skip to content

Commit

Permalink
Improve the filter test for ResourceServletTest to expose Issue jetty…
Browse files Browse the repository at this point in the history
  • Loading branch information
Spikhalskiy committed Feb 5, 2025
1 parent 19214f7 commit 8054950
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

Expand Down Expand Up @@ -2407,6 +2408,7 @@ public void testOutputStreamAndCharsetFiltered() throws Exception
assertThat(response, containsHeaderValue(HttpHeader.CONTENT_LENGTH, String.valueOf(body.length())));
assertThat(response, containsHeaderValue(HttpHeader.CONTENT_TYPE, "text/plain;charset=UTF-8"));
assertThat(body, containsString("Extra Info"));
assertThat("https://github.com/jetty/jetty.project/issues/12766", response, containsHeaderValue(OutputFilter.POST_DO_FILTER_HEADER_NAME, "true"));

rawResponse = connector.getResponse("""
GET /context/image.jpg HTTP/1.1\r
Expand All @@ -2420,6 +2422,7 @@ public void testOutputStreamAndCharsetFiltered() throws Exception
assertThat(response, containsHeaderValue(HttpHeader.CONTENT_LENGTH, String.valueOf(body.length())));
assertThat(response, containsHeaderValue(HttpHeader.CONTENT_TYPE, "image/jpeg;charset=utf-8"));
assertThat(body, containsString("Extra Info"));
assertThat("https://github.com/jetty/jetty.project/issues/12766", response, containsHeaderValue(OutputFilter.POST_DO_FILTER_HEADER_NAME, "true"));
}

/**
Expand Down Expand Up @@ -3555,6 +3558,8 @@ private static String decompressGzip(byte[] compressedContent) throws IOExceptio

public static class OutputFilter implements Filter
{
public static final String POST_DO_FILTER_HEADER_NAME = "OutputFilterPostDoFilter";

@Override
public void init(FilterConfig filterConfig)
{
Expand All @@ -3566,6 +3571,9 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
response.getOutputStream().println("Extra Info");
response.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
assertFalse(response.isCommitted());
// https://github.com/jetty/jetty.project/issues/12766
((HttpServletResponse)response).addHeader(POST_DO_FILTER_HEADER_NAME, "true");
}
}

Expand Down

0 comments on commit 8054950

Please sign in to comment.