Class HttpUtils

java.lang.Object
com.netflix.zuul.util.HttpUtils

public class HttpUtils extends Object
User: Mike Smith Date: 4/28/15 Time: 11:05 PM
  • Constructor Details

    • HttpUtils

      public HttpUtils()
  • Method Details

    • getClientIP

      public static String getClientIP(HttpRequestInfo request)
      Get the IP address of client making the request. Uses the "x-forwarded-for" HTTP header if available, otherwise uses the remote IP of requester.
      Parameters:
      request - HttpRequestMessage
      Returns:
      String IP address
    • extractClientIpFromXForwardedFor

      public static String extractClientIpFromXForwardedFor(String xForwardedFor)
      Extract the client IP address from an x-forwarded-for header. Returns null if there is no x-forwarded-for header
      Parameters:
      xForwardedFor - a String value
      Returns:
      a String value
    • isCompressed

      public static boolean isCompressed(Headers headers)
    • acceptsGzip

      public static boolean acceptsGzip(Headers headers)
    • stripMaliciousHeaderChars

      public static String stripMaliciousHeaderChars(@Nullable String input)
      Ensure decoded new lines are not propagated in headers, in order to prevent XSS
      Parameters:
      input - - decoded header string
      Returns:
      - clean header string
    • hasNonZeroContentLengthHeader

      public static boolean hasNonZeroContentLengthHeader(ZuulMessage msg)
    • getContentLengthIfPresent

      public static Integer getContentLengthIfPresent(ZuulMessage msg)
    • getBodySizeIfKnown

      public static Integer getBodySizeIfKnown(ZuulMessage msg)
    • hasChunkedTransferEncodingHeader

      public static boolean hasChunkedTransferEncodingHeader(ZuulMessage msg)
    • getMainChannel

      public static io.netty.channel.Channel getMainChannel(io.netty.channel.ChannelHandlerContext ctx)
      If http/1 then will always want to just use ChannelHandlerContext.channel(), but for http/2 will want the parent channel (as the child channel is different for each h2 stream).
    • getMainChannel

      public static io.netty.channel.Channel getMainChannel(io.netty.channel.Channel channel)