Package io.karatelabs.http
Class HttpUtils
java.lang.Object
io.karatelabs.http.HttpUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuild a URI with query parameters from a path and params map.static StringextractPath(String uri) Extract just the path portion from a URI (strips query string).static StringextractQueryString(String uri) Extract just the query string from a URI (without the leading '?').static ObjectfromBytes(byte[] bytes, boolean strict, io.karatelabs.common.ResourceType resourceType) static ObjectfromBytesDeclared(byte[] bytes, io.karatelabs.common.ResourceType resourceType) Convert per the declared resource type only — theconfigure strictResponseParsing = truelane (seeHttpResponse.getBodyConverted()).static ObjectfromString(String raw, boolean strict, io.karatelabs.common.ResourceType resourceType) static StringnormaliseUriPath(String uri) static CharsetparseContentTypeCharset(String mimeType) parseContentTypeParams(String mimeType) static io.karatelabs.common.Pair<Object> parsePathAndParams(String uri) Parse a URI path that may contain query parameters.parseQueryParams(String uri) Parse query string parameters from a URI.static io.karatelabs.common.Pair<String> parseUriIntoUrlBaseAndPath(String rawUri) parseUriPattern(String pattern, String url)
-
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
-
parseContentTypeParams
-
parseUriPattern
-
normaliseUriPath
-
parseUriIntoUrlBaseAndPath
-
fromBytes
public static Object fromBytes(byte[] bytes, boolean strict, io.karatelabs.common.ResourceType resourceType) -
fromString
-
fromBytesDeclared
public static Object fromBytesDeclared(byte[] bytes, io.karatelabs.common.ResourceType resourceType) Convert per the declared resource type only — theconfigure strictResponseParsing = truelane (seeHttpResponse.getBodyConverted()). No first-character sniffing: a JSON-shaped body declaredtext/plainstays 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. Anullresource type (no Content-Type declared) falls back to the sniffing conversion: nothing is declared, so there is nothing to be strict about. -
parsePathAndParams
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
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
Extract just the path portion from a URI (strips query string). -
extractQueryString
Extract just the query string from a URI (without the leading '?'). Returns null if no query string present. -
parseQueryParams
Parse query string parameters from a URI. Returns empty map if no query string present.
-