diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java index f1e7134471a3..8294645d50bc 100644 --- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/AbstractProxyServlet.java @@ -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); diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java index 78c8c18aa61a..e75be8d059e1 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java @@ -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 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, "")) + .timeout(5, TimeUnit.SECONDS) + .send(); + + assertEquals(200, response.getStatus()); + assertEquals("", response.getHeaders().get(emptyHeaderName)); + } + /** * Only tests overridden ProxyServlet behavior, see CachingProxyServlet */