Move AsciiLowerCaseSet to jetty-util & changes from review
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
2f23c5936e
commit
f2abf21df6
|
@ -21,9 +21,9 @@ package org.eclipse.jetty.server.handler.gzip;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
|
@ -44,6 +44,7 @@ import org.eclipse.jetty.http.pathmap.PathSpecSet;
|
||||||
import org.eclipse.jetty.server.HttpOutput;
|
import org.eclipse.jetty.server.HttpOutput;
|
||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||||
|
import org.eclipse.jetty.util.AsciiLowerCaseSet;
|
||||||
import org.eclipse.jetty.util.IncludeExclude;
|
import org.eclipse.jetty.util.IncludeExclude;
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
import org.eclipse.jetty.util.compression.CompressionPool;
|
import org.eclipse.jetty.util.compression.CompressionPool;
|
||||||
|
@ -172,7 +173,7 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
||||||
// non-static, as other GzipHandler instances may have different configurations
|
// non-static, as other GzipHandler instances may have different configurations
|
||||||
private final IncludeExclude<String> _methods = new IncludeExclude<>();
|
private final IncludeExclude<String> _methods = new IncludeExclude<>();
|
||||||
private final IncludeExclude<String> _paths = new IncludeExclude<>(PathSpecSet.class);
|
private final IncludeExclude<String> _paths = new IncludeExclude<>(PathSpecSet.class);
|
||||||
private final IncludeExclude<String> _mimeTypes = new IncludeExclude<>(CaseInsensitiveSet.class);
|
private final IncludeExclude<String> _mimeTypes = new IncludeExclude<>(AsciiLowerCaseSet.class);
|
||||||
private HttpField _vary = GzipHttpOutputInterceptor.VARY_ACCEPT_ENCODING;
|
private HttpField _vary = GzipHttpOutputInterceptor.VARY_ACCEPT_ENCODING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -780,10 +781,10 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
||||||
*/
|
*/
|
||||||
public void setDispatcherTypes(String... dispatchers)
|
public void setDispatcherTypes(String... dispatchers)
|
||||||
{
|
{
|
||||||
setDispatcherTypes(Stream.of(dispatchers)
|
_dispatchers = EnumSet.copyOf(Stream.of(dispatchers)
|
||||||
.flatMap(s -> Stream.of(StringUtil.csvSplit(s)))
|
.flatMap(s -> Stream.of(StringUtil.csvSplit(s)))
|
||||||
.map(DispatcherType::valueOf)
|
.map(DispatcherType::valueOf)
|
||||||
.toArray(DispatcherType[]::new));
|
.collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -941,21 +942,4 @@ public class GzipHandler extends HandlerWrapper implements GzipFactory
|
||||||
{
|
{
|
||||||
return String.format("%s@%x{%s,min=%s,inflate=%s}", getClass().getSimpleName(), hashCode(), getState(), _minGzipSize, _inflateBufferSize);
|
return String.format("%s@%x{%s,min=%s,inflate=%s}", getClass().getSimpleName(), hashCode(), getState(), _minGzipSize, _inflateBufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CaseInsensitiveSet extends HashSet<String>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean add(String s)
|
|
||||||
{
|
|
||||||
return super.add(s == null ? null : s.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(Object o)
|
|
||||||
{
|
|
||||||
if (o instanceof String)
|
|
||||||
return super.contains(((String)o).toLowerCase());
|
|
||||||
return super.contains(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -354,6 +354,8 @@ public class GzipHttpOutputInterceptor implements HttpOutput.Interceptor
|
||||||
int off = slice.arrayOffset() + slice.position();
|
int off = slice.arrayOffset() + slice.position();
|
||||||
int len = slice.remaining();
|
int len = slice.remaining();
|
||||||
_crc.update(array, off, len);
|
_crc.update(array, off, len);
|
||||||
|
// Ideally we would want to use the ByteBuffer API for Deflaters. However due the the ByteBuffer implementation
|
||||||
|
// of the CRC32.update() it is less efficient for us to use this rather than to convert to array ourselves.
|
||||||
_deflater.setInput(array, off, len);
|
_deflater.setInput(array, off, len);
|
||||||
slice.position(slice.position() + len);
|
slice.position(slice.position() + len);
|
||||||
if (_last && BufferUtil.isEmpty(_content))
|
if (_last && BufferUtil.isEmpty(_content))
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||||
|
//
|
||||||
|
// This program and the accompanying materials are made available under
|
||||||
|
// the terms of the Eclipse Public License 2.0 which is available at
|
||||||
|
// https://www.eclipse.org/legal/epl-2.0
|
||||||
|
//
|
||||||
|
// This Source Code may also be made available under the following
|
||||||
|
// Secondary Licenses when the conditions for such availability set
|
||||||
|
// forth in the Eclipse Public License, v. 2.0 are satisfied:
|
||||||
|
// the Apache License v2.0 which is available at
|
||||||
|
// https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.util;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class AsciiLowerCaseSet extends HashSet<String>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean add(String s)
|
||||||
|
{
|
||||||
|
return super.add(s == null ? null : StringUtil.asciiToLowerCase(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Object o)
|
||||||
|
{
|
||||||
|
if (o instanceof String)
|
||||||
|
return super.contains(StringUtil.asciiToLowerCase((String)o));
|
||||||
|
return super.contains(o);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue