diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTokens.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTokens.java index 3d1fa984813..725722fd259 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTokens.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTokens.java @@ -257,10 +257,9 @@ public class HttpTokens return ' '; default: - if (c >= 256 || c < ' ') + if (isIllegalFieldVchar(c)) return '?'; } - return c; } diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java index 2bd270829e2..bc7cc82998d 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MetaData.java @@ -15,7 +15,6 @@ package org.eclipse.jetty.http; import java.util.Collections; import java.util.Iterator; -import java.util.Objects; import java.util.function.Supplier; public class MetaData implements Iterable @@ -101,28 +100,6 @@ public class MetaData implements Iterable return _fields.iterator(); } - @Override - public int hashCode() - { - return Objects.hash(_httpVersion, _contentLength, _fields, _trailerSupplier); - } - - @Override - public boolean equals(Object obj) - { - if (!(obj instanceof MetaData)) - return false; - - MetaData other = (MetaData)obj; - if (!Objects.equals(_httpVersion, other._httpVersion)) - return false; - if (!Objects.equals(_contentLength, other._contentLength)) - return false; - if (!Objects.equals(_fields, other._fields)) - return false; - return _trailerSupplier == null && other._trailerSupplier == null; - } - @Override public String toString() { diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanDecoder.java b/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanDecoder.java index b03da0e171b..983e10a9847 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanDecoder.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanDecoder.java @@ -29,7 +29,7 @@ import static org.eclipse.jetty.http.compression.Huffman.rowsym; */ public class HuffmanDecoder { - private final CharsetStringBuilder.Iso8859StringBuilder _builder = new CharsetStringBuilder.Iso8859StringBuilder(); + private final CharsetStringBuilder.Iso88591StringBuilder _builder = new CharsetStringBuilder.Iso88591StringBuilder(); private int _length = 0; private int _count = 0; private int _node = 0; diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanEncoder.java b/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanEncoder.java index c10e7d37f32..965f90ad017 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanEncoder.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/compression/HuffmanEncoder.java @@ -69,7 +69,7 @@ public class HuffmanEncoder * @param s the string to encode in lowercase. * @return the number of octets needed to encode the string, or -1 if it cannot be encoded. */ - public static int octetsNeededLowercase(String s) + public static int octetsNeededLowerCase(String s) { return octetsNeeded(LCCODES, s); } @@ -78,7 +78,7 @@ public class HuffmanEncoder * @param buffer the buffer to encode into in lowercase. * @param s the string to encode. */ - public static void encodeLowercase(ByteBuffer buffer, String s) + public static void encodeLowerCase(ByteBuffer buffer, String s) { encode(LCCODES, buffer, s); } diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/compression/NBitStringParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/compression/NBitStringParser.java index fadc45d0988..0f67df93364 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/compression/NBitStringParser.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/compression/NBitStringParser.java @@ -31,7 +31,7 @@ public class NBitStringParser { private final NBitIntegerParser _integerParser; private final HuffmanDecoder _huffmanBuilder; - private final CharsetStringBuilder.Iso8859StringBuilder _builder; + private final CharsetStringBuilder.Iso88591StringBuilder _builder; private boolean _huffman; private int _count; private int _length; @@ -50,7 +50,7 @@ public class NBitStringParser { _integerParser = new NBitIntegerParser(); _huffmanBuilder = new HuffmanDecoder(); - _builder = new CharsetStringBuilder.Iso8859StringBuilder(); + _builder = new CharsetStringBuilder.Iso88591StringBuilder(); } /** diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java index d6982480d12..cee75446f15 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackDecoder.java @@ -173,7 +173,7 @@ public class HpackDecoder if (huffmanName) name = huffmanDecode(buffer, length); else - name = toISO8859String(buffer, length); + name = toISO88591String(buffer, length); check: for (int i = name.length(); i-- > 0; ) { @@ -213,7 +213,7 @@ public class HpackDecoder if (huffmanValue) value = huffmanDecode(buffer, length); else - value = toISO8859String(buffer, length); + value = toISO88591String(buffer, length); // Make the new field HttpField field; @@ -321,12 +321,12 @@ public class HpackDecoder } } - public static String toISO8859String(ByteBuffer buffer, int length) + public static String toISO88591String(ByteBuffer buffer, int length) { - CharsetStringBuilder.Iso8859StringBuilder builder = new CharsetStringBuilder.Iso8859StringBuilder(); + CharsetStringBuilder.Iso88591StringBuilder builder = new CharsetStringBuilder.Iso88591StringBuilder(); for (int i = 0; i < length; ++i) { - builder.append((char)(0x7F & buffer.get())); + builder.append(HttpTokens.sanitizeFieldVchar((char)buffer.get())); } return builder.build(); } diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java index 77b486a17f4..e84bdb4e367 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java @@ -441,8 +441,8 @@ public class HpackEncoder // leave name index bits as 0 // Encode the name always with lowercase huffman buffer.put((byte)0x80); - NBitIntegerEncoder.encode(buffer, 7, HuffmanEncoder.octetsNeededLowercase(name)); - HuffmanEncoder.encodeLowercase(buffer, name); + NBitIntegerEncoder.encode(buffer, 7, HuffmanEncoder.octetsNeededLowerCase(name)); + HuffmanEncoder.encodeLowerCase(buffer, name); } else { diff --git a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackFieldPreEncoder.java b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackFieldPreEncoder.java index 3b924f0368b..d3e5f7fddde 100644 --- a/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackFieldPreEncoder.java +++ b/jetty-http2/http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackFieldPreEncoder.java @@ -73,8 +73,8 @@ public class HpackFieldPreEncoder implements HttpFieldPreEncoder else { buffer.put((byte)0x80); - NBitIntegerEncoder.encode(buffer, 7, HuffmanEncoder.octetsNeededLowercase(name)); - HuffmanEncoder.encodeLowercase(buffer, name); + NBitIntegerEncoder.encode(buffer, 7, HuffmanEncoder.octetsNeededLowerCase(name)); + HuffmanEncoder.encodeLowerCase(buffer, name); } HpackEncoder.encodeValue(buffer, huffman, value); diff --git a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/QpackTestUtil.java b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/QpackTestUtil.java index 5125867646b..04f699e8e1a 100644 --- a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/QpackTestUtil.java +++ b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/QpackTestUtil.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.http3.qpack; import java.nio.ByteBuffer; import java.util.List; +import java.util.Objects; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; @@ -127,4 +128,15 @@ public class QpackTestUtil { return new MetaData(HttpVersion.HTTP_3, fields); } + + public static boolean compareMetaData(MetaData m1, MetaData m2) + { + if (!Objects.equals(m1.getHttpVersion(), m2.getHttpVersion())) + return false; + if (!Objects.equals(m1.getContentLength(), m2.getContentLength())) + return false; + if (!Objects.equals(m1.getFields(), m2.getFields())) + return false; + return m1.getTrailerSupplier() == null && m2.getTrailerSupplier() == null; + } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/CharsetStringBuilder.java b/jetty-util/src/main/java/org/eclipse/jetty/util/CharsetStringBuilder.java index 9aa2d783cd6..341f39fda07 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/CharsetStringBuilder.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/CharsetStringBuilder.java @@ -79,7 +79,7 @@ public interface CharsetStringBuilder { Objects.requireNonNull(charset); if (charset == StandardCharsets.ISO_8859_1) - return new Iso8859StringBuilder(); + return new Iso88591StringBuilder(); if (charset == StandardCharsets.US_ASCII) return new UsAsciiStringBuilder(); @@ -87,7 +87,7 @@ public interface CharsetStringBuilder return new DecoderStringBuilder(charset.newDecoder()); } - class Iso8859StringBuilder implements CharsetStringBuilder + class Iso88591StringBuilder implements CharsetStringBuilder { private final StringBuilder _builder = new StringBuilder(); @@ -275,5 +275,3 @@ public interface CharsetStringBuilder } } } - -