Issue #6728 - QUIC and HTTP/3
- Fixed charset encoding handling. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
dc889bd7d8
commit
b93436d0e8
|
@ -17,8 +17,6 @@ import java.io.IOException;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -47,7 +45,6 @@ public class QuicheConnection
|
|||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(QuicheConnection.class);
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||
private static final Charset APPLICATION_PROTOCOL_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
static
|
||||
{
|
||||
|
@ -106,9 +103,9 @@ public class QuicheConnection
|
|||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String proto : applicationProtos)
|
||||
sb.append((char)proto.getBytes(APPLICATION_PROTOCOL_CHARSET).length).append(proto);
|
||||
sb.append((char)proto.getBytes(LibQuiche.CHARSET).length).append(proto);
|
||||
String theProtos = sb.toString();
|
||||
LibQuiche.INSTANCE.quiche_config_set_application_protos(quicheConfig, theProtos, new size_t(theProtos.getBytes(APPLICATION_PROTOCOL_CHARSET).length));
|
||||
LibQuiche.INSTANCE.quiche_config_set_application_protos(quicheConfig, theProtos, new size_t(theProtos.getBytes(LibQuiche.CHARSET).length));
|
||||
}
|
||||
|
||||
QuicheConfig.CongestionControl cc = config.getCongestionControl();
|
||||
|
@ -476,7 +473,7 @@ public class QuicheConnection
|
|||
char_pointer out = new char_pointer();
|
||||
size_t_pointer outLen = new size_t_pointer();
|
||||
LibQuiche.INSTANCE.quiche_conn_application_proto(quicheConn, out, outLen);
|
||||
return out.getValueAsString((int)outLen.getValue(), APPLICATION_PROTOCOL_CHARSET);
|
||||
return out.getValueAsString((int)outLen.getValue(), LibQuiche.CHARSET);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -490,7 +487,8 @@ public class QuicheConnection
|
|||
LOG.debug("connection was released");
|
||||
return false;
|
||||
}
|
||||
int rc = LibQuiche.INSTANCE.quiche_conn_close(quicheConn, true, new uint64_t(error), reason, new size_t(reason == null ? 0 : reason.length()));
|
||||
int length = reason == null ? 0 : reason.getBytes(LibQuiche.CHARSET).length;
|
||||
int rc = LibQuiche.INSTANCE.quiche_conn_close(quicheConn, true, new uint64_t(error), reason, new size_t(length));
|
||||
if (rc == 0)
|
||||
return true;
|
||||
if (rc == LibQuiche.quiche_error.QUICHE_ERR_DONE)
|
||||
|
@ -635,8 +633,8 @@ public class QuicheConnection
|
|||
uint64_t_pointer error = new uint64_t_pointer();
|
||||
char_pointer reason = new char_pointer();
|
||||
size_t_pointer reasonLength = new size_t_pointer();
|
||||
if (LibQuiche.INSTANCE.quiche_conn_peer_error(quicheConn, app, error, reason.getPointer(), reasonLength))
|
||||
return new AtomicStampedReference<>(reason.getValueAsString((int)reasonLength.getValue(), StandardCharsets.UTF_8), (int)error.getValue());
|
||||
if (LibQuiche.INSTANCE.quiche_conn_peer_error(quicheConn, app, error, reason, reasonLength))
|
||||
return new AtomicStampedReference<>(reason.getValueAsString((int)reasonLength.getValue(), LibQuiche.CHARSET), (int)error.getValue());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class QuicheConnectionId
|
|||
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
||||
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars, StandardCharsets.UTF_8);
|
||||
return new String(hexChars, StandardCharsets.US_ASCII);
|
||||
}
|
||||
|
||||
public static QuicheConnectionId fromCid(byte[] cid)
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
package org.eclipse.jetty.quic.quiche.ffi;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.sun.jna.Callback;
|
||||
|
@ -31,7 +34,8 @@ public interface LibQuiche extends Library
|
|||
String EXPECTED_QUICHE_VERSION = "0.10.0";
|
||||
|
||||
// load the native lib
|
||||
LibQuiche INSTANCE = Native.load("quiche", LibQuiche.class);
|
||||
Charset CHARSET = StandardCharsets.UTF_8;
|
||||
LibQuiche INSTANCE = Native.load("quiche", LibQuiche.class, Map.of(Library.OPTION_STRING_ENCODING, CHARSET.name()));
|
||||
|
||||
class Logging
|
||||
{
|
||||
|
@ -433,7 +437,7 @@ public interface LibQuiche extends Library
|
|||
boolean quiche_conn_peer_error(quiche_conn conn,
|
||||
bool_pointer is_app,
|
||||
uint64_t_pointer error_code,
|
||||
Pointer/*const uint8_t ***/ reason,
|
||||
char_pointer/*const uint8_t ***/ reason,
|
||||
size_t_pointer reason_len);
|
||||
|
||||
// Returns true if a connection error was queued or sent, and updates the provided
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
|
@ -252,8 +251,8 @@ public class LowLevelQuicheTest
|
|||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String proto : clientQuicheConfig.getApplicationProtos())
|
||||
sb.append((char)proto.getBytes(StandardCharsets.UTF_8).length).append(proto);
|
||||
int protosLen = sb.toString().getBytes(StandardCharsets.UTF_8).length;
|
||||
sb.append((char)proto.getBytes(LibQuiche.CHARSET).length).append(proto);
|
||||
int protosLen = sb.toString().getBytes(LibQuiche.CHARSET).length;
|
||||
|
||||
drainServerToFeedClient(entry, 300 + protosLen);
|
||||
assertThat(serverQuicheConnection.isConnectionEstablished(), is(false));
|
||||
|
|
Loading…
Reference in New Issue