Skip to content

Commit

Permalink
Issue 4068 Empty Encoding fix
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam committed Feb 26, 2019
1 parent 08c5fa2 commit f387933
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -104,6 +104,9 @@ public void filter(ContainerRequestContext request, ContainerResponseContext res
// convert encodings from String to Encoding objects
List<ContentEncoding> encodings = new ArrayList<>();
for (String input : acceptEncoding) {
if (input.isEmpty()) {
continue;
}
String[] tokens = input.split(",");
for (String token : tokens) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,24 +16,23 @@

package org.glassfish.jersey.server.filter;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.message.GZipEncoder;
import org.glassfish.jersey.server.ApplicationHandler;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.ContainerResponse;
import org.glassfish.jersey.server.RequestContextBuilder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.spi.ContentEncoder;

import org.junit.Test;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -82,6 +81,11 @@ public void testNoAcceptEncodingHeader() throws IOException {
testEncoding(null);
}

@Test
public void testEmptyEncodingHeader() throws IOException {
testEncoding(null, "", "", "", "");
}

@Test
public void testAcceptEncodingHeaderNotSupported() throws IOException {
testEncoding(null, "not-gzip");
Expand Down Expand Up @@ -119,7 +123,7 @@ public void testIdentityPreferred() throws IOException {

@Test
public void testAnyAcceptableExceptGZipAndIdentity() throws IOException {
testEncoding("foo", "*", "gzip; q=0", "identity; q=0");
testEncoding("foo", "", "", "", "*", "gzip; q=0", "identity; q=0");
}

@Test
Expand Down

0 comments on commit f387933

Please sign in to comment.