Skip to content

Commit 6d08699

Browse files
sumitsharma0999mslipper
authored andcommitted
Removing hard equality check for gzip encoding header (#245)
Fixes #242
1 parent d749762 commit 6d08699

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/com/googlecode/jsonrpc4j/JsonRpcServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private InputStream getRequestStream(HttpServletRequest request) throws IOExcept
174174
private int handleRequest0(InputStream input, OutputStream output, String contentEncoding, HttpServletResponse response, ByteArrayOutputStream byteOutput) throws IOException {
175175
int result;
176176

177-
boolean canGzipResponse = contentEncoding != null && GZIP.equalsIgnoreCase(contentEncoding);
177+
boolean canGzipResponse = contentEncoding != null && contentEncoding.contains(GZIP);
178178
// Use gzip if client's accept-encoding is set to gzip and gzipResponses is enabled.
179179
if (gzipResponses && canGzipResponse) {
180180
response.addHeader(CONTENT_ENCODING, GZIP);

src/test/java/com/googlecode/jsonrpc4j/server/JsonRpcServerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,25 @@ public void testGzipResponse() throws IOException {
186186
Assert.assertEquals("gzip", response.getHeader(CONTENT_ENCODING));
187187
}
188188

189+
@Test
190+
public void testGzipResponseMultipleAcceptEncoding() throws IOException {
191+
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test-post");
192+
request.addHeader(ACCEPT_ENCODING, "gzip,deflate");
193+
request.setContentType("application/json");
194+
request.setContent("{\"jsonrpc\":\"2.0\",\"id\":123,\"method\":\"testMethod\",\"params\":[\"Whir?inaki\"]}".getBytes(StandardCharsets.UTF_8));
195+
196+
MockHttpServletResponse response = new MockHttpServletResponse();
197+
198+
jsonRpcServer = new JsonRpcServer(Util.mapper, mockService, ServiceInterface.class, true);
199+
jsonRpcServer.handle(request, response);
200+
201+
byte[] compressed = response.getContentAsByteArray();
202+
String sb = getCompressedResponseContent(compressed);
203+
204+
Assert.assertEquals(sb, "{\"jsonrpc\":\"2.0\",\"id\":123,\"result\":null}");
205+
Assert.assertEquals("gzip", response.getHeader(CONTENT_ENCODING));
206+
}
207+
189208
@Test
190209
public void testCorruptRequest() throws Exception {
191210
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/test-post");

0 commit comments

Comments
 (0)