Class GenericHeaderService
- All Implemented Interfaces:
HeaderService
Generic HeaderService implementation.
This implementation uses multiple HTTP header codecs to encode/decode various HTTP headers based on their name.
The GenericHeaderCodec is used when no other codec supports the header to encode/decode.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHeader codecs socket. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a generic header service.GenericHeaderService(List<HeaderCodec<?>> codecs) Creates a generic header service with the specified list of HTTP header codecs. -
Method Summary
Modifier and TypeMethodDescription<T extends Header>
TDecodes the specified header fieldByteBufas defined by RFC 7230 Section 3.2 using the specified charset.<T extends Header>
TDecodes the specified header field as defined by RFC 7230 Section 3.2.<T extends Header>
TDecodes the specified raw valueByteBuffor the specified header name using the specified charset.<T extends Header>
TDecodes the specified raw header value for the specified header name.encode(T header) Encodes the specified header as a string.<T extends Header>
voidEncodes the specified header in the specifiedByteBufferusing the specified charset.encodeValue(T header) Encodes the value of the specified header as a string.<T extends Header>
voidencodeValue(T header, io.netty.buffer.ByteBuf buffer, Charset charset) Encodes the value of the specified header in the specifiedByteBufferusing the specified charset.<T extends Header>
Optional<HeaderCodec<T>> getHeaderCodec(String name) Returns the header codec for the specified header name.voidsetHeaderCodecs(List<HeaderCodec<?>> codecs) Sets the header codecs used to encode and decode headers.
-
Constructor Details
-
GenericHeaderService
Creates a generic header service.
- Throws:
IllegalStateException
-
GenericHeaderService
Creates a generic header service with the specified list of HTTP header codecs.
- Parameters:
codecs- a list of header codecs- Throws:
IllegalArgumentException- if multiple codecs supporting the same header name have been specified.
-
-
Method Details
-
setHeaderCodecs
Sets the header codecs used to encode and decode headers.
- Parameters:
codecs- a list of header codecs- Throws:
IllegalArgumentException- if multiple codecs supporting the same header name have been specified.
-
decode
Description copied from interface:HeaderServiceDecodes the specified header field as defined by RFC 7230 Section 3.2.
- Specified by:
decodein interfaceHeaderService- Type Parameters:
T- the decoded header type- Parameters:
header- a raw header field- Returns:
- a decoded header instance
-
decode
Description copied from interface:HeaderServiceDecodes the specified header field
ByteBufas defined by RFC 7230 Section 3.2 using the specified charset.- Specified by:
decodein interfaceHeaderService- Type Parameters:
T- the decoded header type- Parameters:
buffer- a raw header fieldcharset- the charset to use for decoding- Returns:
- a decoded header instance
-
encode
Description copied from interface:HeaderServiceEncodes the specified header as a string.
The resulting value is a header field as defined by RFC 7230 Section 3.2.
- Specified by:
encodein interfaceHeaderService- Type Parameters:
T- the encoded header type- Parameters:
header- the header to encode- Returns:
- the encoded header string
-
encode
Description copied from interface:HeaderServiceEncodes the specified header in the specified
ByteBufferusing the specified charset.The resulting value is a header field as defined by RFC 7230 Section 3.2.
- Specified by:
encodein interfaceHeaderService- Type Parameters:
T- the encoded header type- Parameters:
header- the header to encodebuffer- the destination byte buffercharset- the charset to use for encoding
-
decode
Description copied from interface:HeaderServiceDecodes the specified raw header value for the specified header name.
- Specified by:
decodein interfaceHeaderService- Type Parameters:
T- the decoded header type- Parameters:
name- a header namevalue- a header raw value- Returns:
- a decoded header instance
-
decode
Description copied from interface:HeaderServiceDecodes the specified raw value
ByteBuffor the specified header name using the specified charset.- Specified by:
decodein interfaceHeaderService- Type Parameters:
T- the decoded header type- Parameters:
name- a header namebuffer- a header raw valuecharset- the charset to use for decoding- Returns:
- a decoded header instance
-
encodeValue
Description copied from interface:HeaderServiceEncodes the value of the specified header as a string.
The resulting value corresponds to the header field value as defined by RFC 7230 Section 3.2.
- Specified by:
encodeValuein interfaceHeaderService- Type Parameters:
T- the encoded header type- Parameters:
header- the header to encode- Returns:
- the encoded header value
-
encodeValue
public <T extends Header> void encodeValue(T header, io.netty.buffer.ByteBuf buffer, Charset charset) Description copied from interface:HeaderServiceEncodes the value of the specified header in the specified
ByteBufferusing the specified charset.The resulting value corresponds to the header field value as defined by RFC 7230 Section 3.2.
- Specified by:
encodeValuein interfaceHeaderService- Type Parameters:
T- the encoded header type- Parameters:
header- the header to encodebuffer- the destination byte buffercharset- the charset to use for encoding
-
getHeaderCodec
Returns the header codec for the specified header name.
- Type Parameters:
T- the header type- Parameters:
name- the header name- Returns:
- an optional returning the header codec or an empty optional if there's no codec for the specified header name
-