Package io.muserver

Class ForwardedHeader


  • public class ForwardedHeader
    extends java.lang.Object

    Represents a Forwarded header as described by RFC-7239.

    • Constructor Summary

      Constructors 
      Constructor Description
      ForwardedHeader​(java.lang.String by, java.lang.String forValue, java.lang.String host, java.lang.String proto, java.util.Map<java.lang.String,​java.lang.String> extensions)
      Creates a new Forwarded Header.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String by()  
      boolean equals​(java.lang.Object o)  
      java.util.Map<java.lang.String,​java.lang.String> extensions()  
      java.lang.String forValue()  
      static java.util.List<ForwardedHeader> fromString​(java.lang.String input)
      Parses the value of a Forwarded header into an object.
      int hashCode()  
      java.lang.String host()  
      java.lang.String proto()  
      java.lang.String toString()
      Converts the HeaderValue into a string, suitable for printing in an HTTP header.
      static java.lang.String toString​(java.util.List<ForwardedHeader> headers)
      Converts a list of headers into a single string that can be put into a Forwarded header field.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ForwardedHeader

        public ForwardedHeader​(java.lang.String by,
                               java.lang.String forValue,
                               java.lang.String host,
                               java.lang.String proto,
                               java.util.Map<java.lang.String,​java.lang.String> extensions)
        Creates a new Forwarded Header. All values are optional.
        Parameters:
        by - The address of the node proxying the request, or null
        forValue - The address of the client that initiated the request, or null
        host - The host that the client used, or null
        proto - The protocol the client used, or null
        extensions - Any extensions, or null
    • Method Detail

      • by

        public java.lang.String by()
        Returns:
        The interface where the request came in to the proxy server (e.g. the IP address of the reverse proxy that forwarded this request), or null if not specified.
      • forValue

        public java.lang.String forValue()
        Returns:
        The interface where the request came in to the proxy server, e.g. the IP address of the client that originated the request), or null if not specified.
      • host

        public java.lang.String host()
        Returns:
        The Host request header field as received by the proxy (e.g. the hostname used on the original request), or null if not specified.
      • proto

        public java.lang.String proto()
        Returns:
        Indicates which protocol was used to make the request (typically "http" or "https"), or null if not specified.
      • extensions

        public java.util.Map<java.lang.String,​java.lang.String> extensions()
        Returns:
        Values not covered by by, for, host, or proto.
      • fromString

        public static java.util.List<ForwardedHeader> fromString​(java.lang.String input)

        Parses the value of a Forwarded header into an object.

        Where multiple reverse proxies have resulted in multiple Forwarded headers, the first value in the list should contain the information of the original request.

        Null or blank strings return an empty list.

        Parameters:
        input - The value to parse
        Returns:
        A list of ForwardedHeader objects
        Throws:
        java.lang.IllegalArgumentException - The value cannot be parsed
      • toString

        public java.lang.String toString()
        Converts the HeaderValue into a string, suitable for printing in an HTTP header.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String, such as "some-value" or "content-type:text/html;charset=UTF-8"
      • toString

        public static java.lang.String toString​(java.util.List<ForwardedHeader> headers)
        Converts a list of headers into a single string that can be put into a Forwarded header field.
        Parameters:
        headers - The headers to serialise
        Returns:
        An RFC-7239 compliant Forwarded header value.
      • 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