Interface ResponseHeadersBuilder

All Superinterfaces:
HttpHeadersBuilder, Iterable<Map.Entry<AsciiString,​String>>

public interface ResponseHeadersBuilder
extends HttpHeadersBuilder
Builds a ResponseHeaders.
See Also:
ResponseHeaders.builder(), ResponseHeaders.toBuilder()
  • Method Details

    • build

      Returns a newly created ResponseHeaders with the entries in this builder.
      Specified by:
      build in interface HttpHeadersBuilder
      Throws:
      IllegalStateException - if this builder does not have ":status" header set.
    • status

      ResponseHeadersBuilder status​(int statusCode)
      Sets the ":status" header.
    • status

      Sets the ":status" header.
    • cookie

      ResponseHeadersBuilder cookie​(Cookie cookie)
      Sets the set-cookie header.
    • cookies

      ResponseHeadersBuilder cookies​(Iterable<? extends Cookie> cookies)
      Sets the set-cookie header.
    • cookies

      ResponseHeadersBuilder cookies​(Cookie... cookies)
      Sets the set-cookie header.
    • sizeHint

      ResponseHeadersBuilder sizeHint​(int sizeHint)
      Description copied from interface: HttpHeadersBuilder
      Specifies the hint about the number of headers which may improve the memory efficiency and performance of the underlying data structure.
      Specified by:
      sizeHint in interface HttpHeadersBuilder
      Returns:
      this
    • endOfStream

      ResponseHeadersBuilder endOfStream​(boolean endOfStream)
      Description copied from interface: HttpHeadersBuilder
      Sets whether the headers will be the last frame in an HTTP/2 stream.
      Specified by:
      endOfStream in interface HttpHeadersBuilder
    • contentType

      ResponseHeadersBuilder contentType​(MediaType contentType)
      Description copied from interface: HttpHeadersBuilder
      Sets the "content-type" header.
      Specified by:
      contentType in interface HttpHeadersBuilder
    • contentDisposition

      ResponseHeadersBuilder contentDisposition​(ContentDisposition contentDisposition)
      Description copied from interface: HttpHeadersBuilder
      Sets the "content-disposition" header.
      Specified by:
      contentDisposition in interface HttpHeadersBuilder
    • add

      Description copied from interface: HttpHeadersBuilder
      Adds a new header with the specified name and value.
      Specified by:
      add in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • add

      Description copied from interface: HttpHeadersBuilder
      Adds new headers with the specified name and values. This method is semantically equivalent to
      
       for (String value : values) {
           builder.add(name, value);
       }
       
      Specified by:
      add in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • add

      ResponseHeadersBuilder add​(CharSequence name, String... values)
      Description copied from interface: HttpHeadersBuilder
      Adds new headers with the specified name and values. This method is semantically equivalent to
      
       for (String value : values) {
           builder.add(name, value);
       }
       
      Specified by:
      add in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • add

      ResponseHeadersBuilder add​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Description copied from interface: HttpHeadersBuilder
      Adds all header names and values of the specified entries.
      Specified by:
      add in interface HttpHeadersBuilder
      Returns:
      this
    • add

      default ResponseHeadersBuilder add​(Map<? extends CharSequence,​String> entries)
      Description copied from interface: HttpHeadersBuilder
      Adds all header names and values of the specified entries.
      Specified by:
      add in interface HttpHeadersBuilder
      Returns:
      this
    • addObject

      ResponseHeadersBuilder addObject​(CharSequence name, Object value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header. The specified header value is converted into a String, as explained in Specifying a non-String header value.
      Specified by:
      addObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addObject

      ResponseHeadersBuilder addObject​(CharSequence name, Iterable<?> values)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header with the specified name and values. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Specified by:
      addObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • addObject

      ResponseHeadersBuilder addObject​(CharSequence name, Object... values)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header with the specified name and values. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Specified by:
      addObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • addObject

      ResponseHeadersBuilder addObject​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> entries)
      Description copied from interface: HttpHeadersBuilder
      Adds all header names and values of the specified entries. The specified header values are converted into Strings, as explained in Specifying a non-String header value.
      Specified by:
      addObject in interface HttpHeadersBuilder
      Returns:
      this
    • addInt

      ResponseHeadersBuilder addInt​(CharSequence name, int value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addInt in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addLong

      ResponseHeadersBuilder addLong​(CharSequence name, long value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addLong in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addFloat

      ResponseHeadersBuilder addFloat​(CharSequence name, float value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addFloat in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addDouble

      ResponseHeadersBuilder addDouble​(CharSequence name, double value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addDouble in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addTimeMillis

      ResponseHeadersBuilder addTimeMillis​(CharSequence name, long value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addTimeMillis in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • set

      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name and value. Any existing headers with the same name are overwritten.
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • set

      Description copied from interface: HttpHeadersBuilder
      Sets a new header with the specified name and values. This method is equivalent to
      
       builder.remove(name);
       for (String v : values) {
           builder.add(name, v);
       }
       
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • set

      ResponseHeadersBuilder set​(CharSequence name, String... values)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name and values. Any existing headers with the specified name are removed. This method is equivalent to:
      
       builder.remove(name);
       for (String v : values) {
           builder.add(name, v);
       }
       
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • set

      ResponseHeadersBuilder set​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Description copied from interface: HttpHeadersBuilder
      Retains all current headers but calls HttpHeadersBuilder.set(CharSequence, String) for each header in the specified entries.
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      entries - the headers used to set the header values
      Returns:
      this
    • set

      default ResponseHeadersBuilder set​(Map<? extends CharSequence,​String> entries)
      Description copied from interface: HttpHeadersBuilder
      Retains all current headers but calls HttpHeadersBuilder.set(CharSequence, String) for each header in the specified entries.
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      entries - the headers used to set the header values
      Returns:
      this
    • setIfAbsent

      ResponseHeadersBuilder setIfAbsent​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Description copied from interface: HttpHeadersBuilder
      Copies the entries missing in this headers from the specified entries. This method is a shortcut for:
      
       headers.names().forEach(name -> {
           if (!builder.contains(name)) {
               builder.set(name, headers.getAll(name));
           }
       });
       
      Specified by:
      setIfAbsent in interface HttpHeadersBuilder
      Returns:
      this
    • setObject

      ResponseHeadersBuilder setObject​(CharSequence name, Object value)
      Description copied from interface: HttpHeadersBuilder
      Sets a new header. Any existing headers with the specified name are removed. The specified header value is converted into a String, as explained in Specifying a non-String header value.
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the value of the header
      Returns:
      this
    • setObject

      ResponseHeadersBuilder setObject​(CharSequence name, Iterable<?> values)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name and values. Any existing headers with the specified name are removed. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       builder.remove(name);
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the values of the header
      Returns:
      this
    • setObject

      ResponseHeadersBuilder setObject​(CharSequence name, Object... values)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name and values. Any existing headers with the specified name are removed. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       builder.remove(name);
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the values of the header
      Returns:
      this
    • setObject

      ResponseHeadersBuilder setObject​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> entries)
      Description copied from interface: HttpHeadersBuilder
      Retains all current headers but calls HttpHeadersBuilder.setObject(CharSequence, Object) for each entry in the specified entries. The specified header values are converted into Strings, as explained in Specifying a non-String header value.
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      entries - the headers used to set the values in this instance
      Returns:
      this
    • setInt

      ResponseHeadersBuilder setInt​(CharSequence name, int value)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Specified by:
      setInt in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setLong

      ResponseHeadersBuilder setLong​(CharSequence name, long value)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Specified by:
      setLong in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setFloat

      ResponseHeadersBuilder setFloat​(CharSequence name, float value)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Specified by:
      setFloat in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setDouble

      ResponseHeadersBuilder setDouble​(CharSequence name, double value)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Specified by:
      setDouble in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setTimeMillis

      ResponseHeadersBuilder setTimeMillis​(CharSequence name, long value)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Specified by:
      setTimeMillis in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • removeAndThen

      ResponseHeadersBuilder removeAndThen​(CharSequence name)
      Description copied from interface: HttpHeadersBuilder
      Removes all headers with the specified name. Unlike HttpHeadersBuilder.remove(CharSequence) this method returns itself so that the caller can chain the invocations.
      Specified by:
      removeAndThen in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      Returns:
      this
    • clear

      Description copied from interface: HttpHeadersBuilder
      Removes all headers. After a call to this method, size() becomes 0.
      Specified by:
      clear in interface HttpHeadersBuilder
      Returns:
      this
    • isEndOfStream

      boolean isEndOfStream()
      Tells whether the headers correspond to the last frame in an HTTP/2 stream.
    • contentType

      @Nullable MediaType contentType()
      Returns the parsed "content-type" header.
      Returns:
      the parsed MediaType if present and valid, or null otherwise.
    • contentDisposition

      @Nullable ContentDisposition contentDisposition()
      Returns the parsed "content-disposition" header.
      Returns:
      the parsed MediaType if present and valid. null if not present or failed to parse "content-disposition" header.
    • get

      @Nullable String get​(CharSequence name)
      Returns the value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the first header value if the header is found, or null if there's no such header
    • get

      String get​(CharSequence name, String defaultValue)
      Returns the value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the first header value or defaultValue if there is no such header
    • getAll

      List<String> getAll​(CharSequence name)
      Returns all values for the header with the specified name. The returned List can't be modified.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      a List of header values or an empty List if there is no such header.
    • getInt

      @Nullable Integer getInt​(CharSequence name)
      Returns the int value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the int value of the first value in insertion order or null if there is no such header or it can't be converted to int.
    • getInt

      int getInt​(CharSequence name, int defaultValue)
      Returns the int value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the int value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to int.
    • getLong

      @Nullable Long getLong​(CharSequence name)
      Returns the long value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the long value of the first value in insertion order or null if there is no such header or it can't be converted to long.
    • getLong

      long getLong​(CharSequence name, long defaultValue)
      Returns the long value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the long value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to long.
    • getFloat

      @Nullable Float getFloat​(CharSequence name)
      Returns the float value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the float value of the first value in insertion order or null if there is no such header or it can't be converted to float.
    • getFloat

      float getFloat​(CharSequence name, float defaultValue)
      Returns the float value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the float value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to float.
    • getDouble

      @Nullable Double getDouble​(CharSequence name)
      Returns the double value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the double value of the first value in insertion order or null if there is no such header or it can't be converted to double.
    • getDouble

      double getDouble​(CharSequence name, double defaultValue)
      Returns the double value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the double value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to double.
    • getTimeMillis

      @Nullable Long getTimeMillis​(CharSequence name)
      Returns the value of a header with the specified name in milliseconds. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the milliseconds value of the first value in insertion order or null if there is no such header or it can't be converted to milliseconds.
    • getTimeMillis

      long getTimeMillis​(CharSequence name, long defaultValue)
      Returns the value of a header with the specified name in milliseconds. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the milliseconds value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to milliseconds.
    • contains

      boolean contains​(CharSequence name)
      Returns true if a header with the name exists, false otherwise.
      Parameters:
      name - the header name
    • contains

      boolean contains​(CharSequence name, String value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value of the header to find
    • containsObject

      boolean containsObject​(CharSequence name, Object value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsInt

      boolean containsInt​(CharSequence name, int value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsLong

      boolean containsLong​(CharSequence name, long value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsFloat

      boolean containsFloat​(CharSequence name, float value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsDouble

      boolean containsDouble​(CharSequence name, double value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsTimeMillis

      boolean containsTimeMillis​(CharSequence name, long value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • size

      int size()
      Returns the number of headers.
    • isEmpty

      boolean isEmpty()
      Returns true if this headers does not contain any entries.
    • names

      Set<AsciiString> names()
      Returns a Set of all header names. The returned Set cannot be modified.
    • iterator

      Returns an Iterator that yields all header entries. The iteration order is as follows:
      1. All pseudo headers (order not specified).
      2. All non-pseudo headers (in insertion order).
      Specified by:
      iterator in interface Iterable<Map.Entry<AsciiString,​String>>
    • valueIterator

      Iterator<String> valueIterator​(CharSequence name)
      Returns an Iterator that yields all values of the headers with the specified name.
    • forEach

      void forEach​(BiConsumer<AsciiString,​String> action)
      Invokes the specified action for all header entries.
    • forEachValue

      void forEachValue​(CharSequence name, Consumer<String> action)
      Invokes the specified action for all values of the headers with the specified name.
    • stream

      default Stream<Map.Entry<AsciiString,​String>> stream()
      Returns a Stream that yields all header entries.
    • valueStream

      default Stream<String> valueStream​(CharSequence name)
      Returns a Stream that yields all values of the headers with the specified name.
    • status

      HttpStatus status()
      Returns the value of the ":status" header as an HttpStatus. If the value is malformed, HttpStatus.UNKNOWN will be returned.
      Throws:
      IllegalStateException - if there is no such header.
    • cookies

      Cookies cookies()
      Returns the parsed set-cookie header.
      Returns:
      a Cookies or an empty Cookies if there is no such header.