Class HttpHeaderMap

    • Field Detail

      • SEPARATOR_KEY_VALUE

        public static final String SEPARATOR_KEY_VALUE
        The separator between key and value
        See Also:
        Constant Field Values
      • DEFAULT_QUOTE_IF_NECESSARY

        public static final boolean DEFAULT_QUOTE_IF_NECESSARY
        Default quote if necessary: false (since v10)
        See Also:
        Constant Field Values
    • Constructor Detail

      • HttpHeaderMap

        public HttpHeaderMap()
        Default constructor.
      • HttpHeaderMap

        public HttpHeaderMap​(@Nonnull
                             HttpHeaderMap aOther)
        Copy constructor.
        Parameters:
        aOther - Map to copy from. May not be null.
    • Method Detail

      • getUnifiedValue

        @Nonnull
        public static String getUnifiedValue​(@Nullable
                                             String sValue)
        Avoid having header values spanning multiple lines. This has been deprecated by RFC 7230 and Jetty 9.3 refuses to parse these requests with HTTP 400 by default.
        Since v9.3.6 this method also takes care of quoting header values correctly. If the value does not correspond to a token according to RFC 2616 chapter 2.2, the value is enclosed in double quotes.
        Parameters:
        sValue - The source header value. May be null.
        Returns:
        The unified header value without \r, \n and \t. Never null.
      • getUnifiedValue

        @Nonnull
        public static String getUnifiedValue​(@Nullable
                                             String sValue,
                                             boolean bQuoteIfNecessary)
        Avoid having header values spanning multiple lines. This has been deprecated by RFC 7230 and Jetty 9.3 refuses to parse these requests with HTTP 400 by default.
        Parameters:
        sValue - The source header value. May be null.
        bQuoteIfNecessary - true if automatic quoting according to RFC 2616, chapter 2.2 should be used if necessary.
        Returns:
        The unified header value without \r, \n and \t. Never null.
        Since:
        9.3.6
      • setHeader

        public void setHeader​(@Nonnull @Nonempty
                              String sName,
                              @Nullable
                              String sValue)
        Set the passed header as is.
        Parameters:
        sName - Header name. May neither be null nor empty.
        sValue - The value to be set. May be null in which case nothing happens.
      • addHeader

        public void addHeader​(@Nonnull @Nonempty
                              String sName,
                              @Nullable
                              String sValue)
        Add the passed header as is.
        Parameters:
        sName - Header name. May neither be null nor empty.
        sValue - The value to be set. May be null in which case nothing happens.
      • setDateHeader

        public void setDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  long nMillis)
        Set the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        nMillis - The milliseconds to set as a date.
      • setDateHeader

        public void setDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  @Nonnull
                                  LocalDate aLD)
        Set the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        aLD - The LocalDate to set as a date. The time is set to start of day. May not be null.
      • setDateHeader

        public void setDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  @Nonnull
                                  LocalDateTime aLDT)
        Set the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        aLDT - The LocalDateTime to set as a date. May not be null.
      • setDateHeader

        public void setDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  @Nonnull
                                  ZonedDateTime aDT)
        Set the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        aDT - The DateTime to set as a date. May not be null.
      • addDateHeader

        public void addDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  long nMillis)
        Add the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        nMillis - The milliseconds to set as a date.
      • addDateHeader

        public void addDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  @Nonnull
                                  LocalDate aLD)
        Add the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        aLD - The LocalDate to set as a date. The time is set to start of day. May not be null.
      • addDateHeader

        public void addDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  @Nonnull
                                  LocalDateTime aLDT)
        Add the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        aLDT - The LocalDateTime to set as a date. May not be null.
      • addDateHeader

        public void addDateHeader​(@Nonnull @Nonempty
                                  String sName,
                                  @Nonnull
                                  ZonedDateTime aDT)
        Add the passed header as a date header.
        Parameters:
        sName - Header name. May neither be null nor empty.
        aDT - The DateTime to set as a date. May not be null.
      • setIntHeader

        public void setIntHeader​(@Nonnull @Nonempty
                                 String sName,
                                 int nValue)
        Set the passed header as a number.
        Parameters:
        sName - Header name. May neither be null nor empty.
        nValue - The value to be set. May not be null.
      • addIntHeader

        public void addIntHeader​(@Nonnull @Nonempty
                                 String sName,
                                 int nValue)
        Add the passed header as a number.
        Parameters:
        sName - Header name. May neither be null nor empty.
        nValue - The value to be set. May not be null.
      • setLongHeader

        public void setLongHeader​(@Nonnull @Nonempty
                                  String sName,
                                  long nValue)
        Set the passed header as a number.
        Parameters:
        sName - Header name. May neither be null nor empty.
        nValue - The value to be set. May not be null.
      • addLongHeader

        public void addLongHeader​(@Nonnull @Nonempty
                                  String sName,
                                  long nValue)
        Add the passed header as a number.
        Parameters:
        sName - Header name. May neither be null nor empty.
        nValue - The value to be set. May not be null.
      • setAllHeaders

        public void setAllHeaders​(@Nonnull
                                  HttpHeaderMap aOther)
        Set all headers from the passed map. Existing headers with the same name are overwritten. Existing headers are not changed!
        Parameters:
        aOther - The header map to add. May not be null.
      • addAllHeaders

        public void addAllHeaders​(@Nonnull
                                  HttpHeaderMap aOther)
        Add all headers from the passed map. Existing headers with the same name are extended.
        Parameters:
        aOther - The header map to add. May not be null.
      • getFirstHeaderValue

        @Nullable
        public String getFirstHeaderValue​(@Nullable
                                          String sName)
        Get the first header value of a certain header name. The matching of the name happens case insensitive.
        Parameters:
        sName - The name to be searched. May be null.
        Returns:
        The first matching value or null.
      • getHeaderCombined

        @Nullable
        public String getHeaderCombined​(@Nullable
                                        String sName,
                                        @Nonnull
                                        String sDelimiter)
        Get the header value as a combination of all contained values. The matching of the name happens case insensitive.
        Parameters:
        sName - The header name to retrieve. May be null.
        sDelimiter - The delimiter to be used. May not be null.
        Returns:
        null if no such header is contained.
      • containsHeaders

        public boolean containsHeaders​(@Nullable
                                       String sName)
      • removeHeadersIf

        @Nonnull
        public EChange removeHeadersIf​(@Nonnull
                                       Predicate<? super String> aNameFilter)
        Remove all header values where the name matches the provided filter.
        Parameters:
        aNameFilter - The name filter to be applied. May not be null.
        Returns:
        EChange
      • removeHeaders

        @Nonnull
        public EChange removeHeaders​(@Nullable
                                     String sName)
        Remove all header values with the provided name
        Parameters:
        sName - The name to be removed. May be null.
        Returns:
        EChange
      • size

        @Nonnegative
        public int size()
        Specified by:
        size in interface IHasSize
        Returns:
        The number of contained elements. Always ≥ 0.
      • forEachSingleHeader

        public void forEachSingleHeader​(@Nonnull
                                        BiConsumer<? super String,​? super String> aConsumer,
                                        boolean bUnifyValue)
        Invoke the provided consumer for every name/value pair.
        Parameters:
        aConsumer - Consumer with key and unified value to be invoked. May not be null.
        bUnifyValue - true to unify the values, false if not
        Since:
        9.3.6
        See Also:
        getUnifiedValue(String,boolean)
      • forEachSingleHeader

        public void forEachSingleHeader​(@Nonnull
                                        BiConsumer<? super String,​? super String> aConsumer,
                                        boolean bUnifyValue,
                                        boolean bQuoteIfNecessary)
        Invoke the provided consumer for every name/value pair.
        Parameters:
        aConsumer - Consumer with key and unified value to be invoked. May not be null.
        bUnifyValue - true to unify the values, false if not
        bQuoteIfNecessary - true to automatically quote values if it is necessary, false to not do it. This is only used, if "unify values" is true.
        Since:
        9.3.7
        See Also:
        getUnifiedValue(String, boolean)
      • forEachHeaderLine

        public void forEachHeaderLine​(@Nonnull
                                      Consumer<? super String> aConsumer,
                                      boolean bUnifyValue)
        Invoke the provided consumer for every header line.
        Parameters:
        aConsumer - Consumer with the assembled line to be invoked. May not be null.
        bUnifyValue - true to unify the values, false if not
        Since:
        9.3.6
        See Also:
        getUnifiedValue(String,boolean)
      • forEachHeaderLine

        public void forEachHeaderLine​(@Nonnull
                                      Consumer<? super String> aConsumer,
                                      boolean bUnifyValue,
                                      boolean bQuoteIfNecessary)
        Invoke the provided consumer for every header line.
        Parameters:
        aConsumer - Consumer with the assembled line to be invoked. May not be null.
        bUnifyValue - true to unify the values, false if not.
        bQuoteIfNecessary - true to automatically quote values if it is necessary, false to not do it. This is only used, if "unify values" is true.
        Since:
        9.3.7
        See Also:
        getUnifiedValue(String,boolean)
      • getAllHeaderLines

        @Nonnull
        @ReturnsMutableCopy
        public ICommonsList<String> getAllHeaderLines​(boolean bUnifyValue)
        Get all header lines as a list of strings.
        Parameters:
        bUnifyValue - true to unify the values, false if not
        Returns:
        Never null but maybe an empty list.
      • getAllHeaderLines

        @Nonnull
        @ReturnsMutableCopy
        public ICommonsList<String> getAllHeaderLines​(boolean bUnifyValue,
                                                      boolean bQuoteIfNecessary)
        Get all header lines as a list of strings.
        Parameters:
        bUnifyValue - true to unify the values, false if not
        bQuoteIfNecessary - true to automatically quote values if it is necessary, false to not do it. This is only used, if "unify values" is true.
        Returns:
        Never null but maybe an empty list.
        Since:
        9.3.7
      • setContentLength

        public void setContentLength​(long nLength)
      • setContentType

        public void setContentType​(@Nonnull
                                   String sContentType)
      • getAsMapStringToListString

        @Nonnull
        public Map<String,​List<String>> getAsMapStringToListString()
        Returns:
        The HTTP header map in a different representation. Never null but maybe empty.
        Since:
        10.0
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object