HeadersBlockBuilder Class — netty Architecture
Architecture documentation for the HeadersBlockBuilder class in DefaultHttp2FrameReader.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 23bfb7ca_b352_2c9b_8f62_2e588930d870["HeadersBlockBuilder"] bd6b4c97_c25c_eb7e_f217_235e361db864["DefaultHttp2FrameReader.java"] 23bfb7ca_b352_2c9b_8f62_2e588930d870 -->|defined in| bd6b4c97_c25c_eb7e_f217_235e361db864 f866bb17_c663_fdde_f411_f633c41c3908["headerSizeExceeded()"] 23bfb7ca_b352_2c9b_8f62_2e588930d870 -->|method| f866bb17_c663_fdde_f411_f633c41c3908 d3cf3714_2259_6a41_c730_30d5c2dc9945["addFragment()"] 23bfb7ca_b352_2c9b_8f62_2e588930d870 -->|method| d3cf3714_2259_6a41_c730_30d5c2dc9945 9c832a67_4aa5_fad4_9499_a8cb5351fa19["Http2Headers()"] 23bfb7ca_b352_2c9b_8f62_2e588930d870 -->|method| 9c832a67_4aa5_fad4_9499_a8cb5351fa19 f70b169a_4d94_c46e_6606_c2990694b7b6["close()"] 23bfb7ca_b352_2c9b_8f62_2e588930d870 -->|method| f70b169a_4d94_c46e_6606_c2990694b7b6
Relationship Graph
Source Code
codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java lines 674–750
protected class HeadersBlockBuilder {
private ByteBuf headerBlock;
/**
* The local header size maximum has been exceeded while accumulating bytes.
* @throws Http2Exception A connection error indicating too much data has been received.
*/
private void headerSizeExceeded() throws Http2Exception {
close();
headerListSizeExceeded(headersDecoder.configuration().maxHeaderListSizeGoAway());
}
/**
* Adds a fragment to the block.
*
* @param fragment the fragment of the headers block to be added.
* @param alloc allocator for new blocks if needed.
* @param endOfHeaders flag indicating whether the current frame is the end of the headers.
* This is used for an optimization for when the first fragment is the full
* block. In that case, the buffer is used directly without copying.
*/
final void addFragment(ByteBuf fragment, int len, ByteBufAllocator alloc,
boolean endOfHeaders) throws Http2Exception {
if (headerBlock == null) {
if (len > headersDecoder.configuration().maxHeaderListSizeGoAway()) {
headerSizeExceeded();
}
if (endOfHeaders) {
// Optimization - don't bother copying, just use the buffer as-is. Need
// to retain since we release when the header block is built.
headerBlock = fragment.readRetainedSlice(len);
} else {
headerBlock = alloc.buffer(len).writeBytes(fragment, len);
}
return;
}
if (headersDecoder.configuration().maxHeaderListSizeGoAway() - len <
headerBlock.readableBytes()) {
headerSizeExceeded();
}
if (headerBlock.isWritable(len)) {
// The buffer can hold the requested bytes, just write it directly.
headerBlock.writeBytes(fragment, len);
} else {
// Allocate a new buffer that is big enough to hold the entire header block so far.
ByteBuf buf = alloc.buffer(headerBlock.readableBytes() + len);
buf.writeBytes(headerBlock).writeBytes(fragment, len);
headerBlock.release();
headerBlock = buf;
}
}
/**
* Builds the headers from the completed headers block. After this is called, this builder
* should not be called again.
*/
Http2Headers headers() throws Http2Exception {
try {
return headersDecoder.decodeHeaders(streamId, headerBlock);
} finally {
close();
}
}
/**
* Closes this builder and frees any resources.
*/
void close() {
if (headerBlock != null) {
headerBlock.release();
headerBlock = null;
}
// Clear the member variable pointing at this instance.
headersContinuation = null;
}
}
Source
Frequently Asked Questions
What is the HeadersBlockBuilder class?
HeadersBlockBuilder is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java.
Where is HeadersBlockBuilder defined?
HeadersBlockBuilder is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java at line 674.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free