Class HttpForwardedHeaderParser

java.lang.Object
com.helger.http.header.specific.HttpForwardedHeaderParser

@Immutable public final class HttpForwardedHeaderParser extends Object
Parser for RFC 7239 compliant "Forwarded" header values. This class can parse a forwarded-element string into a HttpForwardedHeaderHop or multiple forwarded elements separated by commas into a list of HttpForwardedHeaderHop objects. The syntax according to RFC 7239 is:
 Forwarded         = 1#forwarded-element
 forwarded-element = [ forwarded-pair ] *( ";" [ forwarded-pair ] )
 forwarded-pair    = token "=" value
 value             = token / quoted-string
 
Multiple forwarded elements are separated by commas to represent multiple hops.
Since:
10.5.1
Author:
Philip Helger
  • Field Details

  • Method Details

    • parseSingleHop

      @Nullable public static HttpForwardedHeaderHop parseSingleHop(@Nullable String sForwardedElement)
      Parse a forwarded-element string according to RFC 7239.
      Parameters:
      sForwardedElement - The forwarded-element string to parse. May be null.
      Returns:
      A new HttpForwardedHeaderHop containing the parsed pairs, or null if parsing failed or the input was invalid.
    • parseMultipleHops

      @Nullable @ReturnsMutableCopy public static com.helger.collection.commons.ICommonsList<HttpForwardedHeaderHop> parseMultipleHops(@Nullable String sForwardedHeaderValue)
      Parse a complete Forwarded header value that may contain multiple forwarded elements separated by commas according to RFC 7239. Each forwarded element represents one hop in the request chain.
      Parameters:
      sForwardedHeaderValue - The complete Forwarded header value to parse. May be null.
      Returns:
      A list of HttpForwardedHeaderHop objects representing each hop, or null if parsing failed. An empty list is returned for empty but valid input.
    • parseAndGetLastHop

      @Nullable @ReturnsMutableCopy public static HttpForwardedHeaderHop parseAndGetLastHop(@Nullable String sForwardedHeaderValue)
      Parse a complete Forwarded header value that may contain multiple forwarded elements separated by commas according to RFC 7239. Each forwarded element represents one hop in the request chain. Return only the last (and most relevant hop)
      Parameters:
      sForwardedHeaderValue - The complete Forwarded header value to parse. May be null.
      Returns:
      A HttpForwardedHeaderHop object representing the last hop, or null if parsing failed.