Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 474366 - JSON response corrupted when default charset is not UTF-8
Gzip filter must obey the response character encoding when constructing a PrintWriter.
- Loading branch information
Showing
4 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ver.tests/src/org/eclipse/orion/server/tests/filters/ExcludedExtensionGzipFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.orion.server.tests.filters; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import org.eclipse.orion.internal.server.core.metastore.SimpleMetaStore; | ||
import org.eclipse.orion.server.servlets.ExcludedExtensionGzipFilter; | ||
import org.eclipse.orion.server.tests.servlets.files.FileSystemTest; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.meterware.httpunit.WebConversation; | ||
import com.meterware.httpunit.WebRequest; | ||
import com.meterware.httpunit.WebResponse; | ||
|
||
/** | ||
* Tests for {@link ExcludedExtensionGzipFilter}. | ||
*/ | ||
public class ExcludedExtensionGzipFilterTest extends FileSystemTest { | ||
private static final String CONTENT_ENCODING = "Content-Encoding"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
webConversation = new WebConversation(); | ||
webConversation.setExceptionsThrownOnErrorStatus(false); | ||
setUpAuthorization(); | ||
createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); | ||
createTestProject(testName.getMethodName()); | ||
} | ||
|
||
@Test | ||
public void testExcludedExtensions() throws Exception { | ||
assertGzipped(getFileResponse("/file/foo.txt")); | ||
assertGzipped(getFileResponse("/file/bar")); | ||
|
||
assertNotGzipped(getFileResponse("/file/baz.gif")); | ||
assertNotGzipped(getFileResponse("/file/qux.png")); | ||
} | ||
|
||
private static void assertGzipped(WebResponse res) throws Exception { | ||
assertEquals("gzip", res.getHeaderField(CONTENT_ENCODING)); | ||
} | ||
|
||
private static void assertNotGzipped(WebResponse res) throws Exception { | ||
assertNotEquals("gzip", res.getHeaderField(CONTENT_ENCODING)); | ||
} | ||
|
||
private WebResponse getFileResponse(String location) throws Exception { | ||
WebRequest request = getGetFilesRequest(location); | ||
WebResponse response = webConversation.getResponse(request); | ||
return response; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters