Class GenericHeaderService

java.lang.Object
io.inverno.mod.http.base.internal.header.GenericHeaderService
All Implemented Interfaces:
HeaderService

public class GenericHeaderService extends Object implements 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:
  • Constructor Details

  • Method Details

    • setHeaderCodecs

      public void setHeaderCodecs(List<HeaderCodec<?>> codecs)

      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

      public <T extends Header> T decode(String header)
      Description copied from interface: HeaderService

      Decodes the specified header field as defined by RFC 7230 Section 3.2.

      Specified by:
      decode in interface HeaderService
      Type Parameters:
      T - the decoded header type
      Parameters:
      header - a raw header field
      Returns:
      a decoded header instance
    • decode

      public <T extends Header> T decode(io.netty.buffer.ByteBuf buffer, Charset charset)
      Description copied from interface: HeaderService

      Decodes the specified header field ByteBuf as defined by RFC 7230 Section 3.2 using the specified charset.

      Specified by:
      decode in interface HeaderService
      Type Parameters:
      T - the decoded header type
      Parameters:
      buffer - a raw header field
      charset - the charset to use for decoding
      Returns:
      a decoded header instance
    • encode

      public <T extends Header> String encode(T header)
      Description copied from interface: HeaderService

      Encodes the specified header as a string.

      The resulting value is a header field as defined by RFC 7230 Section 3.2.

      Specified by:
      encode in interface HeaderService
      Type Parameters:
      T - the encoded header type
      Parameters:
      header - the header to encode
      Returns:
      the encoded header string
    • encode

      public <T extends Header> void encode(T header, io.netty.buffer.ByteBuf buffer, Charset charset)
      Description copied from interface: HeaderService

      Encodes the specified header in the specified ByteBuffer using the specified charset.

      The resulting value is a header field as defined by RFC 7230 Section 3.2.

      Specified by:
      encode in interface HeaderService
      Type Parameters:
      T - the encoded header type
      Parameters:
      header - the header to encode
      buffer - the destination byte buffer
      charset - the charset to use for encoding
    • decode

      public <T extends Header> T decode(String name, String value)
      Description copied from interface: HeaderService

      Decodes the specified raw header value for the specified header name.

      Specified by:
      decode in interface HeaderService
      Type Parameters:
      T - the decoded header type
      Parameters:
      name - a header name
      value - a header raw value
      Returns:
      a decoded header instance
    • decode

      public <T extends Header> T decode(String name, io.netty.buffer.ByteBuf buffer, Charset charset)
      Description copied from interface: HeaderService

      Decodes the specified raw value ByteBuf for the specified header name using the specified charset.

      Specified by:
      decode in interface HeaderService
      Type Parameters:
      T - the decoded header type
      Parameters:
      name - a header name
      buffer - a header raw value
      charset - the charset to use for decoding
      Returns:
      a decoded header instance
    • encodeValue

      public <T extends Header> String encodeValue(T header)
      Description copied from interface: HeaderService

      Encodes 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:
      encodeValue in interface HeaderService
      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: HeaderService

      Encodes the value of the specified header in the specified ByteBuffer using the specified charset.

      The resulting value corresponds to the header field value as defined by RFC 7230 Section 3.2.

      Specified by:
      encodeValue in interface HeaderService
      Type Parameters:
      T - the encoded header type
      Parameters:
      header - the header to encode
      buffer - the destination byte buffer
      charset - the charset to use for encoding
    • getHeaderCodec

      public <T extends Header> Optional<HeaderCodec<T>> getHeaderCodec(String name)

      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