Class Header

java.lang.Object
com.azure.core.util.Header
Direct Known Subclasses:
HttpHeader

public class Header extends Object
Represents a single header to be set on a request.

If multiple header values are added to a request with the same name (case-insensitive), then the values will be appended at the end of the same Header with commas separating them.

  • Constructor Details

    • Header

      public Header(String name, String value)
      Create a Header instance using the provided name and value.
      Parameters:
      name - the name of the header.
      value - the value of the header.
      Throws:
      NullPointerException - if name is null.
    • Header

      public Header(String name, String... values)
      Create a Header instance using the provided name and values.
      Parameters:
      name - the name of the header.
      values - the values of the header.
      Throws:
      NullPointerException - if name is null.
    • Header

      public Header(String name, List<String> values)
      Create a Header instance using the provided name and values.
      Parameters:
      name - the name of the header.
      values - the values of the header.
      Throws:
      NullPointerException - if name is null.
  • Method Details

    • getName

      public String getName()
      Gets the header name.
      Returns:
      the name of this Header
    • getValue

      public String getValue()
      Gets the combined, comma-separated value of this Header, taking into account all values provided.
      Returns:
      the value of this Header
    • getValues

      public String[] getValues()
      Gets the comma separated value as an array. Changes made to this array will not be reflected in the headers.
      Returns:
      the values of this Header that are separated by a comma
    • getValuesList

      public List<String> getValuesList()
      Returns all values associated with this header, represented as an unmodifiable list of strings.
      Returns:
      An unmodifiable list containing all values associated with this header.
    • addValue

      public void addValue(String value)
      Add a new value to the end of the Header.
      Parameters:
      value - the value to add
    • toString

      public String toString()
      Gets the String representation of the header.
      Overrides:
      toString in class Object
      Returns:
      the String representation of this Header.