State() — netty Function Reference
Architecture documentation for the State() function in HttpObjectDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 91c85325_7220_8d93_a39b_91415ca496f4["State()"] 6c551372_1bb2_fe27_3884_c4cc297c86ae["HttpObjectDecoder"] 91c85325_7220_8d93_a39b_91415ca496f4 -->|defined in| 6c551372_1bb2_fe27_3884_c4cc297c86ae 40673f8f_e843_c287_a057_291f8aa2ac4d["splitHeader()"] 91c85325_7220_8d93_a39b_91415ca496f4 -->|calls| 40673f8f_e843_c287_a057_291f8aa2ac4d e8aadc10_5550_f709_7873_e84704f04e88["isDecodingRequest()"] 91c85325_7220_8d93_a39b_91415ca496f4 -->|calls| e8aadc10_5550_f709_7873_e84704f04e88 2f946e86_7691_de33_0f9b_17113f4e73f9["isSwitchingToNonHttp1Protocol()"] 91c85325_7220_8d93_a39b_91415ca496f4 -->|calls| 2f946e86_7691_de33_0f9b_17113f4e73f9 e296a6f9_cccf_f3cd_2a43_a9281d020f61["isContentAlwaysEmpty()"] 91c85325_7220_8d93_a39b_91415ca496f4 -->|calls| e296a6f9_cccf_f3cd_2a43_a9281d020f61 da2c080b_7266_0728_8c0b_d7d4672886ff["handleTransferEncodingChunkedWithContentLength()"] 91c85325_7220_8d93_a39b_91415ca496f4 -->|calls| da2c080b_7266_0728_8c0b_d7d4672886ff style 91c85325_7220_8d93_a39b_91415ca496f4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java lines 740–828
private State readHeaders(ByteBuf buffer) {
final HttpMessage message = this.message;
final HttpHeaders headers = message.headers();
final HeaderParser headerParser = this.headerParser;
ByteBuf line = headerParser.parse(buffer, defaultStrictCRLFCheck);
if (line == null) {
return null;
}
int lineLength = line.readableBytes();
while (lineLength > 0) {
final byte[] lineContent = line.array();
final int startLine = line.arrayOffset() + line.readerIndex();
final byte firstChar = lineContent[startLine];
if (name != null && (firstChar == ' ' || firstChar == '\t')) {
//please do not make one line from below code
//as it breaks +XX:OptimizeStringConcat optimization
String trimmedLine = langAsciiString(lineContent, startLine, lineLength).trim();
String valueStr = value;
value = valueStr + ' ' + trimmedLine;
} else {
if (name != null) {
headers.add(name, value);
}
splitHeader(lineContent, startLine, lineLength);
}
line = headerParser.parse(buffer, defaultStrictCRLFCheck);
if (line == null) {
return null;
}
lineLength = line.readableBytes();
}
// Add the last header.
if (name != null) {
headers.add(name, value);
}
// reset name and value fields
name = null;
value = null;
// Done parsing initial line and headers. Set decoder result.
HttpMessageDecoderResult decoderResult = new HttpMessageDecoderResult(lineParser.size, headerParser.size);
message.setDecoderResult(decoderResult);
List<String> contentLengthFields = headers.getAll(HttpHeaderNames.CONTENT_LENGTH);
if (!contentLengthFields.isEmpty()) {
HttpVersion version = message.protocolVersion();
boolean isHttp10OrEarlier = version.majorVersion() < 1 || (version.majorVersion() == 1
&& version.minorVersion() == 0);
// Guard against multiple Content-Length headers as stated in
// https://tools.ietf.org/html/rfc7230#section-3.3.2:
contentLength = HttpUtil.normalizeAndGetContentLength(contentLengthFields,
isHttp10OrEarlier, allowDuplicateContentLengths);
if (contentLength != -1) {
String lengthValue = contentLengthFields.get(0).trim();
if (contentLengthFields.size() > 1 || // don't unnecessarily re-order headers
!lengthValue.equals(Long.toString(contentLength))) {
headers.set(HttpHeaderNames.CONTENT_LENGTH, contentLength);
}
}
} else {
// We know the content length if it's a Web Socket message even if
// Content-Length header is missing.
contentLength = HttpUtil.getWebSocketContentLength(message);
}
if (!isDecodingRequest() && message instanceof HttpResponse) {
HttpResponse res = (HttpResponse) message;
this.isSwitchingToNonHttp1Protocol = isSwitchingToNonHttp1Protocol(res);
}
if (isContentAlwaysEmpty(message)) {
HttpUtil.setTransferEncodingChunked(message, false);
return State.SKIP_CONTROL_CHARS;
}
if (HttpUtil.isTransferEncodingChunked(message)) {
this.chunked = true;
if (!contentLengthFields.isEmpty() && message.protocolVersion() == HttpVersion.HTTP_1_1) {
handleTransferEncodingChunkedWithContentLength(message);
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does State() do?
State() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java.
Where is State() defined?
State() is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java at line 740.
What does State() call?
State() calls 5 function(s): handleTransferEncodingChunkedWithContentLength, isContentAlwaysEmpty, isDecodingRequest, isSwitchingToNonHttp1Protocol, splitHeader.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free