From 37b6acb74ee491eb26cc45f2237445dceaf0eb43 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 18 Feb 2021 11:39:28 -0600 Subject: [PATCH] Fixing bad merge Signed-off-by: Joakim Erdfelt --- .../rewrite/handler/ForceRequestHeaderValueRule.java | 10 ++++++++-- .../handler/ForceRequestHeaderValueRuleTest.java | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRule.java b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRule.java index e042ceb594c..171ebad18de 100644 --- a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRule.java +++ b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRule.java @@ -22,6 +22,7 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.server.Request; public class ForceRequestHeaderValueRule extends Rule @@ -66,8 +67,13 @@ public class ForceRequestHeaderValueRule extends Rule } Request baseRequest = Request.getBaseRequest(httpServletRequest); - baseRequest.getHttpFields().remove(headerName); - baseRequest.getHttpFields().add(headerName, forcedValue); + if (baseRequest == null) + return null; + + HttpFields.Mutable replacement = HttpFields.build(baseRequest.getHttpFields()) + .remove(headerName) + .add(headerName, forcedValue); + baseRequest.setHttpFields(replacement); return target; } } diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRuleTest.java index 2b5954e6852..a8c8d0e42a2 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ForceRequestHeaderValueRuleTest.java @@ -139,7 +139,7 @@ public class ForceRequestHeaderValueRuleTest public void testThreeAcceptHeadersRequest() throws Exception { rule.setHeaderName("Accept"); - rule.setForcedValue("*/*"); + rule.setForcedValue("text/*"); StringBuilder request = new StringBuilder(); request.append("GET /echo/foo HTTP/1.1\r\n"); @@ -153,7 +153,7 @@ public class ForceRequestHeaderValueRuleTest String rawResponse = connector.getResponse(request.toString()); HttpTester.Response response = HttpTester.parseResponse(rawResponse); assertEquals(200, response.getStatus()); - assertThat(response.getContent(), containsString("[Accept]: [*/*]")); + assertThat(response.getContent(), containsString("[Accept]: [text/*]")); assertThat(response.getContent(), containsString("[Host]: [local]")); assertThat(response.getContent(), containsString("[Connection]: [closed]")); } @@ -162,7 +162,7 @@ public class ForceRequestHeaderValueRuleTest public void testInterleavedAcceptHeadersRequest() throws Exception { rule.setHeaderName("Accept"); - rule.setForcedValue("*/*"); + rule.setForcedValue("application/*"); StringBuilder request = new StringBuilder(); request.append("GET /echo/foo HTTP/1.1\r\n"); @@ -178,7 +178,7 @@ public class ForceRequestHeaderValueRuleTest String rawResponse = connector.getResponse(request.toString()); HttpTester.Response response = HttpTester.parseResponse(rawResponse); assertEquals(200, response.getStatus()); - assertThat(response.getContent(), containsString("[Accept]: [*/*]")); + assertThat(response.getContent(), containsString("[Accept]: [application/*]")); assertThat(response.getContent(), containsString("[Accept-Charset]: [iso-8859-5, unicode-1-1;q=0.8]")); assertThat(response.getContent(), containsString("[Accept-Encoding]: [gzip;q=1.0, identity; q=0.5, *;q=0]")); assertThat(response.getContent(), containsString("[Host]: [local]"));