Utf8FrameValidator Class — netty Architecture
Architecture documentation for the Utf8FrameValidator class in Utf8FrameValidator.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 703786e3_a739_d459_7ab0_6451a2d19cdf["Utf8FrameValidator"] 4c1109e4_821c_255f_c27b_46539b39d849["Utf8FrameValidator.java"] 703786e3_a739_d459_7ab0_6451a2d19cdf -->|defined in| 4c1109e4_821c_255f_c27b_46539b39d849 bad18f93_ba72_83c0_cd03_f1173296b893["Utf8FrameValidator()"] 703786e3_a739_d459_7ab0_6451a2d19cdf -->|method| bad18f93_ba72_83c0_cd03_f1173296b893 b1f436ed_fa46_f58e_f1be_408bd00463e5["isControlFrame()"] 703786e3_a739_d459_7ab0_6451a2d19cdf -->|method| b1f436ed_fa46_f58e_f1be_408bd00463e5 95417fd6_697c_ee9f_be0e_5cdc60d7350f["channelRead()"] 703786e3_a739_d459_7ab0_6451a2d19cdf -->|method| 95417fd6_697c_ee9f_be0e_5cdc60d7350f c5a4f50d_2576_9eef_f670_a6dba4a8f68b["checkUTF8String()"] 703786e3_a739_d459_7ab0_6451a2d19cdf -->|method| c5a4f50d_2576_9eef_f670_a6dba4a8f68b 07b6a241_43f6_47fc_892d_87fcedabf99a["protocolViolation()"] 703786e3_a739_d459_7ab0_6451a2d19cdf -->|method| 07b6a241_43f6_47fc_892d_87fcedabf99a b0fff810_1df7_ea4a_4bed_378099d40cbe["exceptionCaught()"] 703786e3_a739_d459_7ab0_6451a2d19cdf -->|method| b0fff810_1df7_ea4a_4bed_378099d40cbe
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/Utf8FrameValidator.java lines 26–129
public class Utf8FrameValidator extends ChannelInboundHandlerAdapter {
private final boolean closeOnProtocolViolation;
private int fragmentedFramesCount;
private Utf8Validator utf8Validator;
public Utf8FrameValidator() {
this(true);
}
public Utf8FrameValidator(boolean closeOnProtocolViolation) {
this.closeOnProtocolViolation = closeOnProtocolViolation;
}
// See https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.
private static boolean isControlFrame(WebSocketFrame frame) {
return frame instanceof CloseWebSocketFrame ||
frame instanceof PingWebSocketFrame ||
frame instanceof PongWebSocketFrame;
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof WebSocketFrame) {
WebSocketFrame frame = (WebSocketFrame) msg;
try {
// Processing for possible fragmented messages for text and binary
// frames
if (frame.isFinalFragment()) {
// Control frames are allowed between fragments
// See https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.
if (!isControlFrame(frame)) {
// Final frame of the sequence.
fragmentedFramesCount = 0;
// Check text for UTF8 correctness
if (frame instanceof TextWebSocketFrame ||
(utf8Validator != null && utf8Validator.isChecking())) {
// Check UTF-8 correctness for this payload
checkUTF8String(frame.content());
// This does a second check to make sure UTF-8
// correctness for entire text message
utf8Validator.finish();
}
}
} else {
// Not final frame so we can expect more frames in the
// fragmented sequence
if (fragmentedFramesCount == 0) {
// First text or binary frame for a fragmented set
if (frame instanceof TextWebSocketFrame) {
checkUTF8String(frame.content());
}
} else {
// Subsequent frames - only check if init frame is text
if (utf8Validator != null && utf8Validator.isChecking()) {
checkUTF8String(frame.content());
}
}
// Increment counter
fragmentedFramesCount++;
}
} catch (CorruptedWebSocketFrameException e) {
protocolViolation(ctx, frame, e);
}
}
super.channelRead(ctx, msg);
}
private void checkUTF8String(ByteBuf buffer) {
if (utf8Validator == null) {
utf8Validator = new Utf8Validator();
}
utf8Validator.check(buffer);
}
Source
Frequently Asked Questions
What is the Utf8FrameValidator class?
Utf8FrameValidator is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/Utf8FrameValidator.java.
Where is Utf8FrameValidator defined?
Utf8FrameValidator is defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/Utf8FrameValidator.java at line 26.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free