2012-02-02 08:10:28 +01:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2012-02-02 08:10:28 +01:00
|
|
|
package io.netty.handler.codec.http;
|
|
|
|
|
2012-05-31 20:32:42 +02:00
|
|
|
import io.netty.handler.codec.compression.ZlibWrapper;
|
|
|
|
|
2012-02-02 08:10:28 +01:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class HttpContentCompressorTest {
|
|
|
|
@Test
|
|
|
|
public void testGetTargetContentEncoding() throws Exception {
|
|
|
|
HttpContentCompressor compressor = new HttpContentCompressor();
|
|
|
|
|
|
|
|
String[] tests = {
|
|
|
|
// Accept-Encoding -> Content-Encoding
|
|
|
|
"", null,
|
|
|
|
"*", "gzip",
|
|
|
|
"*;q=0.0", null,
|
|
|
|
"gzip", "gzip",
|
|
|
|
"compress, gzip;q=0.5", "gzip",
|
|
|
|
"gzip; q=0.5, identity", "gzip",
|
|
|
|
"gzip ; q=0.1", "gzip",
|
|
|
|
"gzip; q=0, deflate", "deflate",
|
2012-07-19 06:48:26 +02:00
|
|
|
" deflate ; q=0 , *;q=0.5", "gzip",
|
2012-02-02 08:10:28 +01:00
|
|
|
};
|
|
|
|
for (int i = 0; i < tests.length; i += 2) {
|
|
|
|
String acceptEncoding = tests[i];
|
|
|
|
String contentEncoding = tests[i + 1];
|
|
|
|
ZlibWrapper targetWrapper = compressor.determineWrapper(acceptEncoding);
|
|
|
|
String targetEncoding = null;
|
|
|
|
if (targetWrapper != null) {
|
|
|
|
switch (targetWrapper) {
|
|
|
|
case GZIP:
|
|
|
|
targetEncoding = "gzip";
|
|
|
|
break;
|
|
|
|
case ZLIB:
|
|
|
|
targetEncoding = "deflate";
|
|
|
|
break;
|
|
|
|
default:
|
2012-05-31 20:32:42 +02:00
|
|
|
Assert.fail();
|
2012-02-02 08:10:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Assert.assertEquals(contentEncoding, targetEncoding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|