Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #8750 - AbstractProxyServlet.onServerResponseHeaders does not s… #8904

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ protected void onServerResponseHeaders(HttpServletRequest clientRequest, HttpSer
continue;

String newHeaderValue = filterServerResponseHeader(clientRequest, serverResponse, headerName, field.getValue());
if (newHeaderValue == null || newHeaderValue.trim().length() == 0)
if (newHeaderValue == null)
continue;

proxyResponse.addHeader(headerName, newHeaderValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,36 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
assertTrue(response.getHeaders().contains(PROXIED_HEADER));
}

@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyEmptyHeaderValue(AbstractProxyServlet proxyServletClass) throws Exception
{
String emptyHeaderName = "X-Empty";
startServer(new EmptyHttpServlet()
{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
{
assertEquals("", request.getHeader(emptyHeaderName));
response.setHeader(emptyHeaderName, "");
}
});
String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
Map<String, String> initParams = new HashMap<>();
initParams.put("proxyTo", proxyTo);
startProxy(proxyServletClass, initParams);
startClient();

// Make the request to the proxy, it should transparently forward to the server.
ContentResponse response = client.newRequest("localhost", proxyConnector.getLocalPort())
.headers(headers -> headers.put(emptyHeaderName, ""))
joakime marked this conversation as resolved.
Show resolved Hide resolved
.timeout(5, TimeUnit.SECONDS)
.send();

assertEquals(200, response.getStatus());
assertEquals("", response.getHeaders().get(emptyHeaderName));
}

/**
* Only tests overridden ProxyServlet behavior, see CachingProxyServlet
*/
Expand Down