Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http

public final Class HttpClientCodec

extends CombinedChannelDuplexHandler<HttpResponseDecoder, HttpRequestEncoder>
implements SourceCodec
Class Inheritance
All Implemented Interfaces
io.netty5.handler.codec.http.HttpClientUpgradeHandler.SourceCodec
Imports
io.netty5.buffer.Buffer, io.netty5.channel.Channel, .ChannelHandlerContext, .ChannelPipeline, .CombinedChannelDuplexHandler, io.netty5.channel.internal.DelegatingChannelHandlerContext, io.netty5.handler.codec.PrematureChannelClosureException, java.util.ArrayDeque, .List, .Queue, java.util.concurrent.atomic.AtomicLong

A combination of HttpRequestEncoder and HttpResponseDecoder which enables easier client side HTTP implementation. HttpClientCodec provides additional state management for HEAD and CONNECT requests, which HttpResponseDecoder lacks. Please refer to HttpResponseDecoder to learn what additional state management needs to be done for HEAD and CONNECT and why HttpResponseDecoder can not handle it by itself. If the Channel is closed and there are missing responses, a PrematureChannelClosureException is thrown.
See Also
HttpServerCodec

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
public static final boolean
public static final boolean
private boolean
done

If true, decoding stops (i.e. pass-through)

private final boolean
private final boolean
private final Queue<HttpMethod>
queue

A queue that is used for correlating a request and a response.

private final AtomicLong

Constructor Summary

AccessConstructor and Description
public
HttpClientCodec()

Creates a new instance with the default decoder options (maxInitialLineLength (4096}, maxHeaderSize (8192), and maxChunkSize (8192)).

public
HttpClientCodec(int maxInitialLineLength, int maxHeaderSize)

Creates a new instance with the specified decoder options.

public
HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse)

Creates a new instance with the specified decoder options.

public
HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders)

Creates a new instance with the specified decoder options.

public
HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, boolean parseHttpAfterConnectRequest)

Creates a new instance with the specified decoder options.

public
HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize)

Creates a new instance with the specified decoder options.

public
HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest)

Creates a new instance with the specified decoder options.

public
HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths)

Creates a new instance with the specified decoder options.

Method Summary

Modifier and TypeMethod and Description
public boolean
public void
public void
setSingleDecode(boolean singleDecode)

public void
Inherited from io.netty5.channel.CombinedChannelDuplexHandler:
bindchannelActivechannelExceptionCaughtchannelInactivechannelInboundEventchannelReadchannelReadCompletechannelRegisteredchannelShutdownchannelUnregisteredchannelWritabilityChangedcloseconnectderegisterdisconnectflushhandlerAddedhandlerRemovedinboundHandlerinitisSharableoutboundHandlerpendingOutboundBytesreadregisterremoveInboundHandlerremoveOutboundHandlersendOutboundEventshutdownwrite

Field Detail

DEFAULT_FAIL_ON_MISSING_RESPONSEback to summary
public static final boolean DEFAULT_FAIL_ON_MISSING_RESPONSE
DEFAULT_PARSE_HTTP_AFTER_CONNECT_REQUESTback to summary
public static final boolean DEFAULT_PARSE_HTTP_AFTER_CONNECT_REQUEST
doneback to summary
private boolean done

If true, decoding stops (i.e. pass-through)

failOnMissingResponseback to summary
private final boolean failOnMissingResponse
parseHttpAfterConnectRequestback to summary
private final boolean parseHttpAfterConnectRequest
queueback to summary
private final Queue<HttpMethod> queue

A queue that is used for correlating a request and a response.

requestResponseCounterback to summary
private final AtomicLong requestResponseCounter

Constructor Detail

HttpClientCodecback to summary
public HttpClientCodec()

Creates a new instance with the default decoder options (maxInitialLineLength (4096}, maxHeaderSize (8192), and maxChunkSize (8192)).

HttpClientCodecback to summary
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize)

Creates a new instance with the specified decoder options.

HttpClientCodecback to summary
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse)

Creates a new instance with the specified decoder options.

HttpClientCodecback to summary
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders)

Creates a new instance with the specified decoder options.

HttpClientCodecback to summary
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, boolean parseHttpAfterConnectRequest)

Creates a new instance with the specified decoder options.

HttpClientCodecback to summary
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize)

Creates a new instance with the specified decoder options.

HttpClientCodecback to summary
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest)

Creates a new instance with the specified decoder options.

HttpClientCodecback to summary
public HttpClientCodec(int maxInitialLineLength, int maxHeaderSize, boolean failOnMissingResponse, boolean validateHeaders, int initialBufferSize, boolean parseHttpAfterConnectRequest, boolean allowDuplicateContentLengths)

Creates a new instance with the specified decoder options.

Method Detail

isSingleDecodeback to summary
public boolean isSingleDecode()
prepareUpgradeFromback to summary
public void prepareUpgradeFrom(ChannelHandlerContext ctx)

Implements io.netty5.handler.codec.http.HttpClientUpgradeHandler.SourceCodec.prepareUpgradeFrom.

Prepares to upgrade to another protocol from HTTP. Disables the Encoder.

Annotations
@Override
setSingleDecodeback to summary
public void setSingleDecode(boolean singleDecode)
upgradeFromback to summary
public void upgradeFrom(ChannelHandlerContext ctx)

Implements io.netty5.handler.codec.http.HttpClientUpgradeHandler.SourceCodec.upgradeFrom.

Upgrades to another protocol from HTTP. Removes the Decoder and Encoder from the pipeline.

Annotations
@Override
io.netty5.handler.codec.http back to summary

private final Class HttpClientCodec.Decoder

extends HttpResponseDecoder
Class Inheritance

Field Summary

Modifier and TypeField and Description
private ChannelHandlerContext

Constructor Summary

AccessConstructor and Description
pack-priv
Decoder(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders)

pack-priv
Decoder(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths)

Method Summary

Modifier and TypeMethod and Description
public void
channelInactive(ChannelHandlerContext ctx)

Overrides io.netty5.handler.codec.ByteToMessageDecoder.channelInactive.

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
protected void
decode(ChannelHandlerContext ctx, Buffer
the Buffer from which to read data
buffer
)

Overrides io.netty5.handler.codec.http.HttpObjectDecoder.decode.

Decode the from one Buffer to another.
private void
protected void
protected boolean
Inherited from io.netty5.handler.codec.http.HttpResponseDecoder:
createInvalidMessagecreateMessageisDecodingRequest

Field Detail

contextback to summary
private ChannelHandlerContext context

Hides io.netty5.handler.codec.ByteToMessageDecoder.context.

Constructor Detail

Decoderback to summary
pack-priv Decoder(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders)
Decoderback to summary
pack-priv Decoder(int maxInitialLineLength, int maxHeaderSize, boolean validateHeaders, int initialBufferSize, boolean allowDuplicateContentLengths)

Method Detail

channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides io.netty5.handler.codec.ByteToMessageDecoder.channelInactive.

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Annotations
@Override
decodeback to summary
protected void decode(ChannelHandlerContext ctx, Buffer buffer) throws Exception

Overrides io.netty5.handler.codec.http.HttpObjectDecoder.decode.

Doc from io.netty5.handler.codec.ByteToMessageDecoder.decode.

Decode the from one Buffer to another. This method will be called till either the input Buffer has nothing to read when return from this method or till nothing was read from the input Buffer.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this ByteToMessageDecoder belongs to

buffer:Buffer

the Buffer from which to read data

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
decrementback to summary
private void decrement(Object msg)
handlerAdded0back to summary
protected void handlerAdded0(ChannelHandlerContext ctx)

Overrides io.netty5.handler.codec.ByteToMessageDecoder.handlerAdded0.

Annotations
@Override
isContentAlwaysEmptyback to summary
protected boolean isContentAlwaysEmpty(HttpMessage msg)

Overrides io.netty5.handler.codec.http.HttpObjectDecoder.isContentAlwaysEmpty.

Annotations
@Override
io.netty5.handler.codec.http back to summary

private final Class HttpClientCodec.Encoder

extends HttpRequestEncoder
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
encodeAndClose(ChannelHandlerContext ctx, Object
the message to encode to another one.
msg
,
List<Object>
the List into which produced output messages should be added.
out
)

Overrides io.netty5.handler.codec.http.HttpObjectEncoder.encodeAndClose.

Encode from one message to another.
Inherited from io.netty5.handler.codec.http.HttpRequestEncoder:
acceptOutboundMessageencodeInitialLine

Field Detail

upgradedback to summary
pack-priv boolean upgraded

Constructor Detail

Encoderback to summary
private Encoder()

Method Detail

encodeAndCloseback to summary
protected void encodeAndClose(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception

Overrides io.netty5.handler.codec.http.HttpObjectEncoder.encodeAndClose.

Doc from io.netty5.handler.codec.MessageToMessageEncoder.encodeAndClose.

Encode from one message to another. This method will be called for each written message that can be handled by this encoder.

The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.

Subclasses that wish to have incoming messages automatically disposed of should instead override the encode(ChannelHandlerContext, Object, List) method.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageEncoder belongs to.

msg:Object

the message to encode to another one.

out:List<Object>

the List into which produced output messages should be added.

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs.