Package org.takes.rs

Class RsWithHeader

  • All Implemented Interfaces:
    Body, Head, Response

    public final class RsWithHeader
    extends RsWrap
    Response decorator, with an additional header.

    Remember, if a header is already present in the response, this decorator will add another one, with the same name. It doesn't check for duplicates. If you want to avoid duplicate headers, use this decorator in combination with RsWithoutHeader, for example:

     new RsWithHeader(
       new RsWithoutHeader(res, "Host"),
       "Host", "www.example.com"
     )

    In this example, RsWithoutHeader will remove the Host header first and RsWithHeader will add a new one.

    The class is immutable and thread-safe.

    Since:
    0.1
    • Constructor Detail

      • RsWithHeader

        public RsWithHeader​(CharSequence hdr)
        Ctor.
        Parameters:
        hdr - Header
        Since:
        0.8
      • RsWithHeader

        public RsWithHeader​(CharSequence name,
                            CharSequence value)
        Ctor.
        Parameters:
        name - Header name
        value - Header value
        Since:
        0.8
      • RsWithHeader

        public RsWithHeader​(Response res,
                            CharSequence name,
                            CharSequence value)
        Ctor.
        Parameters:
        res - Original response
        name - Header name
        value - Header value
      • RsWithHeader

        public RsWithHeader​(Response res,
                            CharSequence header)
        Ctor.
        Parameters:
        res - Original response
        header - Header to add
      • RsWithHeader

        public RsWithHeader​(Response res,
                            org.cactoos.Scalar<CharSequence> header)
        Ctor.
        Parameters:
        res - Original response
        header - Header to add