Class HttpUtils

java.lang.Object
io.karatelabs.http.HttpUtils

public class HttpUtils extends Object
  • Field Details

    • ZERO_BYTES

      public static final byte[] ZERO_BYTES
    • MEGABYTE

      public static final int MEGABYTE
      See Also:
  • Constructor Details

    • HttpUtils

      public HttpUtils()
  • Method Details

    • parseContentTypeCharset

      public static Charset parseContentTypeCharset(String mimeType)
    • parseContentTypeParams

      public static Map<String,String> parseContentTypeParams(String mimeType)
    • parseUriPattern

      public static Map<String,String> parseUriPattern(String pattern, String url)
    • normaliseUriPath

      public static String normaliseUriPath(String uri)
    • parseUriIntoUrlBaseAndPath

      public static io.karatelabs.common.Pair<String> parseUriIntoUrlBaseAndPath(String rawUri)
    • fromBytes

      public static Object fromBytes(byte[] bytes, boolean strict, io.karatelabs.common.ResourceType resourceType)
    • fromString

      public static Object fromString(String raw, boolean strict, io.karatelabs.common.ResourceType resourceType)
    • fromBytesDeclared

      public static Object fromBytesDeclared(byte[] bytes, io.karatelabs.common.ResourceType resourceType)
      Convert per the declared resource type only — the configure strictResponseParsing = true lane (see HttpResponse.getBodyConverted()). No first-character sniffing: a JSON-shaped body declared text/plain stays a String. Grammar tolerance is unchanged from the lenient lane — only which type drives the conversion differs — so a declared-JSON body that fails to parse falls back to the raw string exactly as before. A null resource type (no Content-Type declared) falls back to the sniffing conversion: nothing is declared, so there is nothing to be strict about.
    • parsePathAndParams

      public static io.karatelabs.common.Pair<Object> parsePathAndParams(String uri)
      Parse a URI path that may contain query parameters. Returns a Pair where left is the path (without query string) and right is the params map.

      Examples: - "/test?name=john" -> Pair.of("/test", {name: [john]}) - "/test" -> Pair.of("/test", {}) - "/api/users?id=1&id=2" -> Pair.of("/api/users", {id: [1, 2]})

    • buildUri

      public static String buildUri(String path, Map<String,List<String>> params)
      Build a URI with query parameters from a path and params map.

      Example: buildUri("/test", Map.of("name", List.of("john"))) -> "/test?name=john"

    • extractPath

      public static String extractPath(String uri)
      Extract just the path portion from a URI (strips query string).
    • extractQueryString

      public static String extractQueryString(String uri)
      Extract just the query string from a URI (without the leading '?'). Returns null if no query string present.
    • parseQueryParams

      public static Map<String,List<String>> parseQueryParams(String uri)
      Parse query string parameters from a URI. Returns empty map if no query string present.