Class HttpUtil

java.lang.Object
org.microproxy.http.HttpUtil

public final class HttpUtil extends Object
Helpers for connection-management and framing headers.
  • Method Details

    • isKeepAlive

      public static boolean isKeepAlive(HttpMessage message)
      Whether the sender of message wants the connection kept open afterwards, following the Connection header and the protocol version's default.
      Parameters:
      message - the message whose connection preference is inspected
      Returns:
      whether the connection should remain open after the message
    • setKeepAlive

      public static void setKeepAlive(HttpMessage message, boolean keepAlive)
      Sets the Connection header so that isKeepAlive(org.microproxy.http.HttpMessage) returns keepAlive.
      Parameters:
      message - the message whose Connection header is updated
      keepAlive - whether the connection should remain open
    • isTransferEncodingChunked

      public static boolean isTransferEncodingChunked(HttpMessage message)
      Whether the final transfer coding is chunked.
      Parameters:
      message - the message whose transfer codings are inspected
      Returns:
      whether chunked is the final transfer coding
    • setTransferEncodingChunked

      public static void setTransferEncodingChunked(HttpMessage message, boolean chunked)
      Makes chunked the final transfer coding (keeping any other codings) and removes Content-Length, or removes chunked again when chunked is false.
      Parameters:
      message - the message whose framing headers are updated
      chunked - whether to append chunked or remove it from the transfer codings
    • getContentLength

      public static long getContentLength(HttpMessage message, long defaultValue)
      The Content-Length value, or defaultValue if absent or invalid.
      Parameters:
      message - the message whose Content-Length is inspected
      defaultValue - the fallback for an absent or unparsable value
      Returns:
      the parsed long value, or defaultValue
    • setContentLength

      public static void setContentLength(HttpMessage message, long length)
      Sets the Content-Length field to the supplied decimal value.
      Parameters:
      message - the message whose Content-Length is updated
      length - the length value to write in decimal
    • is100ContinueExpected

      public static boolean is100ContinueExpected(HttpRequest request)
      Whether the request carries Expect: 100-continue.
      Parameters:
      request - the request whose version and Expect header are inspected
      Returns:
      whether persistence is the protocol default and the request expects 100-continue