Class WarningValue

java.lang.Object
org.apache.hc.client5.http.impl.cache.WarningValue

class WarningValue extends Object
This class provides for parsing and understanding Warning headers. As the Warning header can be multi-valued, but the values can contain separators like commas inside quoted strings, we cannot use the regular NameValuePair.getValue() } call to access the values.
  • Field Details

  • Constructor Details

    • WarningValue

      WarningValue(String s)
    • WarningValue

      WarningValue(String s, int offs)
  • Method Details

    • getWarningValues

      public static WarningValue[] getWarningValues(org.apache.hc.core5.http.Header h)
      Returns an array of the parsable warning values contained in the given header value, which is assumed to be a Warning header. Improperly formatted warning values will be skipped, in keeping with the philosophy of "ignore what you cannot understand."
      Parameters:
      h - Warning Header to parse
      Returns:
      array of WarnValue objects
    • consumeLinearWhitespace

      protected void consumeLinearWhitespace()
    • isChar

      private boolean isChar(char c)
    • isControl

      private boolean isControl(char c)
    • isSeparator

      private boolean isSeparator(char c)
    • consumeToken

      protected void consumeToken()
    • isTokenChar

      private boolean isTokenChar(char c)
    • consumeHostPort

      protected void consumeHostPort()
    • consumeWarnAgent

      protected void consumeWarnAgent()
    • consumeQuotedString

      protected void consumeQuotedString()
    • consumeWarnText

      protected void consumeWarnText()
    • consumeWarnDate

      protected void consumeWarnDate()
    • consumeWarnValue

      protected void consumeWarnValue()
    • consumeCharacter

      protected void consumeCharacter(char c)
    • consumeWarnCode

      protected void consumeWarnCode()
    • parseError

      private void parseError()
    • getWarnCode

      public int getWarnCode()
      Returns the 3-digit code associated with this warning.
      Returns:
      int
    • getWarnAgent

      public String getWarnAgent()
      Returns the "warn-agent" string associated with this warning, which is either the name or pseudonym of the server that added this particular Warning header.
      Returns:
      String
    • getWarnText

      public String getWarnText()
      Returns the human-readable warning text for this warning. Note that the original quoted-string is returned here, including escaping for any contained characters. In other words, if the header was:
         Warning: 110 fred "Response is stale"
       
      then this method will return "\"Response is stale\"" (surrounding quotes included).
      Returns:
      String
    • getWarnDate

      public Instant getWarnDate()
      Returns the date and time when this warning was added, or null if a warning date was not supplied in the header.
      Returns:
      Instant
    • toString

      public String toString()
      Formats a WarningValue as a String suitable for including in a header. For example, you can:
         WarningValue wv = ...;
         HttpResponse resp = ...;
         resp.addHeader("Warning", wv.toString());
       
      Overrides:
      toString in class Object
      Returns:
      String