HttpToHttp2ConnectionHandler Class — netty Architecture
Architecture documentation for the HttpToHttp2ConnectionHandler class in HttpToHttp2ConnectionHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 4447759a_2f71_7328_e5e4_3e3629ebf2c1["HttpToHttp2ConnectionHandler"] da19fb4f_2dea_79a4_ccb3_363cabf1fc7b["HttpToHttp2ConnectionHandler.java"] 4447759a_2f71_7328_e5e4_3e3629ebf2c1 -->|defined in| da19fb4f_2dea_79a4_ccb3_363cabf1fc7b 4852778f_d74f_940d_0191_4f4c247963cd["HttpToHttp2ConnectionHandler()"] 4447759a_2f71_7328_e5e4_3e3629ebf2c1 -->|method| 4852778f_d74f_940d_0191_4f4c247963cd 06d6ae40_b984_beda_b815_22f978264d9c["getStreamId()"] 4447759a_2f71_7328_e5e4_3e3629ebf2c1 -->|method| 06d6ae40_b984_beda_b815_22f978264d9c 7372f9aa_ae7e_50a4_48ab_f253231ab58a["write()"] 4447759a_2f71_7328_e5e4_3e3629ebf2c1 -->|method| 7372f9aa_ae7e_50a4_48ab_f253231ab58a 11c74977_305d_4e4a_d861_36d3c5d33abb["writeHeaders()"] 4447759a_2f71_7328_e5e4_3e3629ebf2c1 -->|method| 11c74977_305d_4e4a_d861_36d3c5d33abb
Relationship Graph
Source Code
codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java lines 36–164
public class HttpToHttp2ConnectionHandler extends Http2ConnectionHandler {
private final boolean validateHeaders;
private int currentStreamId;
private HttpScheme httpScheme;
protected HttpToHttp2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
Http2Settings initialSettings, boolean validateHeaders) {
super(decoder, encoder, initialSettings);
this.validateHeaders = validateHeaders;
}
protected HttpToHttp2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
Http2Settings initialSettings, boolean validateHeaders,
boolean decoupleCloseAndGoAway) {
this(decoder, encoder, initialSettings, validateHeaders, decoupleCloseAndGoAway, null);
}
protected HttpToHttp2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
Http2Settings initialSettings, boolean validateHeaders,
boolean decoupleCloseAndGoAway, HttpScheme httpScheme) {
super(decoder, encoder, initialSettings, decoupleCloseAndGoAway);
this.validateHeaders = validateHeaders;
this.httpScheme = httpScheme;
}
protected HttpToHttp2ConnectionHandler(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder,
Http2Settings initialSettings, boolean validateHeaders,
boolean decoupleCloseAndGoAway, boolean flushPreface,
HttpScheme httpScheme) {
super(decoder, encoder, initialSettings, decoupleCloseAndGoAway, flushPreface);
this.validateHeaders = validateHeaders;
this.httpScheme = httpScheme;
}
/**
* Get the next stream id either from the {@link HttpHeaders} object or HTTP/2 codec
*
* @param httpHeaders The HTTP/1.x headers object to look for the stream id
* @return The stream id to use with this {@link HttpHeaders} object
* @throws Exception If the {@code httpHeaders} object specifies an invalid stream id
*/
private int getStreamId(HttpHeaders httpHeaders) throws Exception {
return httpHeaders.getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(),
connection().local().incrementAndGetNextStreamId());
}
/**
* Handles conversion of {@link HttpMessage} and {@link HttpContent} to HTTP/2 frames.
*/
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
if (!(msg instanceof HttpMessage || msg instanceof HttpContent)) {
ctx.write(msg, promise);
return;
}
boolean release = true;
SimpleChannelPromiseAggregator promiseAggregator =
new SimpleChannelPromiseAggregator(promise, ctx.channel(), ctx.executor());
try {
Http2ConnectionEncoder encoder = encoder();
boolean endStream = false;
if (msg instanceof HttpMessage) {
final HttpMessage httpMsg = (HttpMessage) msg;
// Provide the user the opportunity to specify the streamId
currentStreamId = getStreamId(httpMsg.headers());
// Add HttpScheme if it's defined in constructor and header does not contain it.
if (httpScheme != null &&
!httpMsg.headers().contains(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text())) {
httpMsg.headers().set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), httpScheme.name());
}
// Convert and write the headers.
Http2Headers http2Headers = HttpConversionUtil.toHttp2Headers(httpMsg, validateHeaders);
endStream = msg instanceof FullHttpMessage && !((FullHttpMessage) msg).content().isReadable();
writeHeaders(ctx, encoder, currentStreamId, httpMsg.headers(), http2Headers,
endStream, promiseAggregator);
Source
Frequently Asked Questions
What is the HttpToHttp2ConnectionHandler class?
HttpToHttp2ConnectionHandler is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java.
Where is HttpToHttp2ConnectionHandler defined?
HttpToHttp2ConnectionHandler is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/HttpToHttp2ConnectionHandler.java at line 36.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free