Class HttpHeaders

  • All Implemented Interfaces:
    ToHttpHeaders, java.lang.Iterable<@NonNull HttpHeader>

    public final class HttpHeaders
    extends java.lang.Object
    implements java.lang.Iterable<@NonNull HttpHeader>, ToHttpHeaders
    A collection of multiple HttpHeader objects. There's only one set of values per name so repeated headers must be merged into a single HttpHeader with multiple values. The iteration order of headers is not guaranteed and the order is not preserved.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static @NonNull HttpHeaders EMPTY
      An empty HttpHeaders instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      @NonNull java.util.Optional<@NonNull HttpHeader> get​(@NonNull java.lang.String key)  
      int hashCode()  
      boolean isEmpty()  
      @NonNull java.util.Iterator<@NonNull HttpHeader> iterator()
      Iterate over the headers in this object.
      static @NonNull HttpHeaders of​(@NonNull HttpHeader... headers)
      Create a new HttpHeaders from the given headers.
      static @NonNull HttpHeaders of​(@NonNull java.lang.Iterable<@NonNull HttpHeader> headers)
      Create a new HttpHeaders from the given headers.
      static @NonNull HttpHeaders of​(@NonNull java.util.Iterator<@NonNull HttpHeader> headers)
      Create a new HttpHeaders from the given headers.
      @NonNull java.util.stream.Stream<@NonNull HttpHeader> stream()
      Return a Stream over the headers in this object.
      @NonNull HttpHeaders toHttpHeaders()
      Return HTTP headers for this object.
      java.lang.String toString()  
      @NonNull HttpHeaders update​(@NonNull HttpHeader... headers)
      Return a new HttpHeaders with the given headers updated.
      @NonNull HttpHeaders update​(@NonNull java.lang.Iterable<@NonNull HttpHeader> headers)
      Return a new HttpHeaders with the given headers updated.
      @NonNull HttpHeaders update​(@NonNull java.util.Iterator<@NonNull HttpHeader> headers)
      Return a new HttpHeaders with the given headers updated.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • EMPTY

        @NonNull
        public static final @NonNull HttpHeaders EMPTY
        An empty HttpHeaders instance.
    • Method Detail

      • iterator

        @NonNull
        public @NonNull java.util.Iterator<@NonNull HttpHeader> iterator()
        Iterate over the headers in this object. Iteration order is arbitrary and not guaranteed to be consistent.
        Specified by:
        iterator in interface java.lang.Iterable<@NonNull HttpHeader>
        Returns:
        an iterator over all HttpHeader values in this collection
      • stream

        @NonNull
        public @NonNull java.util.stream.Stream<@NonNull HttpHeader> stream()
        Return a Stream over the headers in this object.
        Returns:
        a Stream over all HttpHeader values in this collection
      • update

        @NonNull
        public @NonNull HttpHeaders update​(@NonNull
                                           @NonNull HttpHeader... headers)
        Return a new HttpHeaders with the given headers updated. Any header names that are already present will be replaced, i.e. values are not merged.
        Parameters:
        headers - the headers to update
        Returns:
        a new HttpHeaders with the given updates
      • update

        @NonNull
        public @NonNull HttpHeaders update​(@NonNull
                                           @NonNull java.lang.Iterable<@NonNull HttpHeader> headers)
        Return a new HttpHeaders with the given headers updated. Any header names that are already present will be replaced, i.e. values are not merged.
        Parameters:
        headers - the headers to update
        Returns:
        a new HttpHeaders with the given updates
      • update

        @NonNull
        public @NonNull HttpHeaders update​(@NonNull
                                           @NonNull java.util.Iterator<@NonNull HttpHeader> headers)
        Return a new HttpHeaders with the given headers updated. Any header names that are already present will be replaced, i.e. values are not merged.
        Parameters:
        headers - the headers to update
        Returns:
        a new HttpHeaders with the given updates
      • isEmpty

        public boolean isEmpty()
        Returns:
        Check if this HttpHeaders is empty.
      • toHttpHeaders

        @NonNull
        public @NonNull HttpHeaders toHttpHeaders()
        Description copied from interface: ToHttpHeaders
        Return HTTP headers for this object.
        Specified by:
        toHttpHeaders in interface ToHttpHeaders
        Returns:
        HTTP headers associated with this object
      • get

        @NonNull
        public @NonNull java.util.Optional<@NonNull HttpHeader> get​(@NonNull
                                                                    @NonNull java.lang.String key)
      • of

        @NonNull
        public static @NonNull HttpHeaders of​(@NonNull
                                              @NonNull HttpHeader... headers)
        Create a new HttpHeaders from the given headers. Only the last value for any given header name will be kept.
        Parameters:
        headers - the headers to include
        Returns:
        a new HttpHeaders from the given headers.
      • of

        @NonNull
        public static @NonNull HttpHeaders of​(@NonNull
                                              @NonNull java.lang.Iterable<@NonNull HttpHeader> headers)
        Create a new HttpHeaders from the given headers. Only the last value for any given header name will be kept.
        Parameters:
        headers - the headers to include
        Returns:
        a new HttpHeaders from the given headers.
      • of

        @NonNull
        public static @NonNull HttpHeaders of​(@NonNull
                                              @NonNull java.util.Iterator<@NonNull HttpHeader> headers)
        Create a new HttpHeaders from the given headers. Only the last value for any given header name will be kept.
        Parameters:
        headers - the headers to include
        Returns:
        the HttpHeaders
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object