decode() — netty Function Reference
Architecture documentation for the decode() function in SpdyHttpDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 9d3e067f_5ad6_e6e1_a9d7_8d35a6ab74ac["decode()"] 025fd5f9_dfbe_4042_6d63_96c1c1168bd5["SpdyHttpDecoder"] 9d3e067f_5ad6_e6e1_a9d7_8d35a6ab74ac -->|defined in| 025fd5f9_dfbe_4042_6d63_96c1c1168bd5 style 9d3e067f_5ad6_e6e1_a9d7_8d35a6ab74ac fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java lines 164–387
@Override
protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out)
throws Exception {
if (msg instanceof SpdySynStreamFrame) {
// HTTP requests/responses are mapped one-to-one to SPDY streams.
SpdySynStreamFrame spdySynStreamFrame = (SpdySynStreamFrame) msg;
int streamId = spdySynStreamFrame.streamId();
if (SpdyCodecUtil.isServerId(streamId)) {
// SYN_STREAM frames initiated by the server are pushed resources
int associatedToStreamId = spdySynStreamFrame.associatedStreamId();
// If a client receives a SYN_STREAM with an Associated-To-Stream-ID of 0
// it must reply with a RST_STREAM with error code INVALID_STREAM.
if (associatedToStreamId == 0) {
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.INVALID_STREAM);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
}
// If a client receives a SYN_STREAM with isLast set,
// reply with a RST_STREAM with error code PROTOCOL_ERROR
// (we only support pushed resources divided into two header blocks).
if (spdySynStreamFrame.isLast()) {
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.PROTOCOL_ERROR);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
}
// If a client receives a response with a truncated header block,
// reply with a RST_STREAM with error code INTERNAL_ERROR.
if (spdySynStreamFrame.isTruncated()) {
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.INTERNAL_ERROR);
ctx.writeAndFlush(spdyRstStreamFrame);
return;
}
try {
FullHttpRequest httpRequestWithEntity = createHttpRequest(spdySynStreamFrame, ctx.alloc());
// Set the Stream-ID, Associated-To-Stream-ID, and Priority as headers
httpRequestWithEntity.headers().setInt(Names.STREAM_ID, streamId);
httpRequestWithEntity.headers().setInt(Names.ASSOCIATED_TO_STREAM_ID, associatedToStreamId);
httpRequestWithEntity.headers().setInt(Names.PRIORITY, spdySynStreamFrame.priority());
out.add(httpRequestWithEntity);
} catch (Throwable ignored) {
SpdyRstStreamFrame spdyRstStreamFrame =
new DefaultSpdyRstStreamFrame(streamId, SpdyStreamStatus.PROTOCOL_ERROR);
ctx.writeAndFlush(spdyRstStreamFrame);
}
} else {
// SYN_STREAM frames initiated by the client are HTTP requests
// If a client sends a request with a truncated header block, the server must
// reply with an HTTP 431 REQUEST HEADER FIELDS TOO LARGE reply.
if (spdySynStreamFrame.isTruncated()) {
SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamId);
spdySynReplyFrame.setLast(true);
SpdyHeaders frameHeaders = spdySynReplyFrame.headers();
frameHeaders.setInt(STATUS, HttpResponseStatus.REQUEST_HEADER_FIELDS_TOO_LARGE.code());
frameHeaders.setObject(VERSION, HttpVersion.HTTP_1_0);
ctx.writeAndFlush(spdySynReplyFrame);
return;
}
try {
FullHttpRequest httpRequestWithEntity = createHttpRequest(spdySynStreamFrame, ctx.alloc());
// Set the Stream-ID as a header
httpRequestWithEntity.headers().setInt(Names.STREAM_ID, streamId);
if (spdySynStreamFrame.isLast()) {
out.add(httpRequestWithEntity);
} else {
// Request body will follow in a series of Data Frames
Domain
Subdomains
Source
Frequently Asked Questions
What does decode() do?
decode() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java.
Where is decode() defined?
decode() is defined in codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java at line 164.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free