From 572eda2d06962d1eee821261d5e847f44e567d19 Mon Sep 17 00:00:00 2001 From: markslater Date: Fri, 8 Apr 2022 22:12:49 +0100 Subject: [PATCH] #7863 Include value of first accept-encoding header where multiple accept-encoding headers are given. Signed-off-by: markslater --- .../java/org/eclipse/jetty/server/ResourceService.java | 1 + .../org/eclipse/jetty/servlet/DefaultServletTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java index e0785ca4a713..694209ca4b2b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResourceService.java @@ -336,6 +336,7 @@ private List getPreferredEncodingOrder(HttpServletRequest request) if (headers.hasMoreElements()) { StringBuilder sb = new StringBuilder(key.length() * 2); + sb.append(key); do { sb.append(',').append(headers.nextElement()); diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java index c84753f2d36f..1acd1f5a5248 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java @@ -1917,6 +1917,16 @@ public void testDefaultBrotliOverGzip() throws Exception assertThat(response, containsHeaderValue(HttpHeader.CONTENT_ENCODING, "gzip")); body = response.getContent(); assertThat(body, containsString("fake gzip")); + + rawResponse = connector.getResponse("GET /context/data0.txt HTTP/1.0\r\nHost:localhost:8080\r\nAccept-Encoding:br\r\nAccept-Encoding:gzip, compress\r\n\r\n"); + response = HttpTester.parseResponse(rawResponse); + assertThat(response.toString(), response.getStatus(), is(HttpStatus.OK_200)); + assertThat(response, containsHeaderValue(HttpHeader.CONTENT_LENGTH, "11")); + assertThat(response, containsHeaderValue(HttpHeader.CONTENT_TYPE, "text/plain")); + assertThat(response, containsHeaderValue(HttpHeader.VARY, "Accept-Encoding")); + assertThat(response, containsHeaderValue(HttpHeader.CONTENT_ENCODING, "br")); + body = response.getContent(); + assertThat(body, containsString("fake brotli")); } @Test