Package io.karatelabs.http
Class HttpRequest
java.lang.Object
io.karatelabs.http.HttpRequest
- All Implemented Interfaces:
io.karatelabs.js.ObjectLike,io.karatelabs.js.SimpleObject
-
Field Summary
Fields inherited from interface io.karatelabs.js.SimpleObject
TO_STRING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]getBody()The body coerced to parsed JSON regardless of content-type: an already-parsedMap/List(a JSON content-type —getBodyConverted()parses those eagerly) is returned as-is; a string body is parsed leniently; anything else (binary, blank, unparsable) isnull.Parse cookies from the Cookie header(s).Canonical multipart-file accessor for server-side templates and handlers.Multi-value multipart-file accessor.getHeaderValues(String name) getMultiPart(String name) Get a single multipart field by name.Get all multipart data.getParamValues(String name) getPath()io.karatelabs.common.ResourceTypebooleanisAjax()Returns true if this is an HTMX/AJAX request (has HX-Request header).booleanReturns true if this request has multipart form data.booleanpathMatches(String pattern) Forward this request to a target URL and return the response.voidProcess the request body for form-urlencoded or multipart data.voidvoidvoidremoveHeader(String name) voidsetBody(byte[] body) voidsetBodyDisplay(String bodyDisplay) voidsetContentType(String contentType) voidsetHeaders(Map<String, List<String>> headers) voidsetHttpClient(HttpClient httpClient) Set theHttpClientused byproceed(String)to forward this request.voidvoidvoidvoidvoidsetUrlBase(String urlBase) toHttpRequestBuilder(HttpClient client) toMap()toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.karatelabs.js.ObjectLike
getMember, getPrototype, isExtensible, isFrozen, isOwnProperty, isSealed, putMember, removeMember, setExtensible, setFrozen, setSealedMethods inherited from interface io.karatelabs.js.SimpleObject
getMember, jsKeys, jsToString, putMember, removeMember
-
Constructor Details
-
HttpRequest
public HttpRequest()
-
-
Method Details
-
setHttpClient
Set theHttpClientused byproceed(String)to forward this request. When not set, a default client is lazily created viaDefaultHttpClientFactory. -
setUrl
-
getUrlAndPath
-
setPath
-
setUrlBase
-
setParams
-
getParams
-
getPath
-
getPathRaw
-
pathMatches
-
getPathParams
-
putHeader
-
putHeader
-
getMethod
-
setMethod
-
getHeaders
-
setHeaders
-
getBody
public byte[] getBody() -
getBodyString
-
getBodyJson
The body coerced to parsed JSON regardless of content-type: an already-parsedMap/List(a JSON content-type —getBodyConverted()parses those eagerly) is returned as-is; a string body is parsed leniently; anything else (binary, blank, unparsable) isnull. The body-side sibling ofparamJson(name)— JS handlers readrequest.bodyJsoninstead of branching ontypeof request.body. -
setBody
public void setBody(byte[] body) -
getBodyDisplay
-
setBodyDisplay
-
getHeaderValues
-
getParamValues
-
getParam
-
removeHeader
-
getHeader
-
getContentType
-
getCookies
Parse cookies from the Cookie header(s). Returns a map where each cookie name maps to a map with 'name' and 'value' keys. This matches V1 behavior where cookies are accessed as: requestCookies['name'].value Handles both single Cookie header with semicolon-separated values, and multiple Cookie headers. -
setContentType
-
getResourceType
public io.karatelabs.common.ResourceType getResourceType() -
isAjax
public boolean isAjax()Returns true if this is an HTMX/AJAX request (has HX-Request header). Used to determine if a partial or full page render is needed. -
isMultiPart
public boolean isMultiPart()Returns true if this request has multipart form data. -
getMultiParts
Get all multipart data. -
getMultiPart
Get a single multipart field by name. Returns the first part with the given name, or null if not found. -
getFile
Canonical multipart-file accessor for server-side templates and handlers. Returns the first uploaded file with the given form-field name, or null if absent. Each returned map carries{name, filename, contentType, charset?, value (byte[]), bytes (byte[] alias), size}. MirrorsgetHeader(String)(first match). -
getFiles
Multi-value multipart-file accessor. Returns ALL uploaded files with the given form-field name, in upload order. Empty list if none. MirrorsgetHeaderValues(String)/getParamValues(String). Use this for<input type="file" multiple>or any form posting repeated file fields under the same name. -
processBody
public void processBody()Process the request body for form-urlencoded or multipart data. For form-urlencoded, fields are merged into params. For multipart, file uploads are stored in multiParts and fields in params. -
getBodyConverted
-
toBlockData
-
toMap
- Specified by:
toMapin interfaceio.karatelabs.js.ObjectLike- Specified by:
toMapin interfaceio.karatelabs.js.SimpleObject
-
toString
-
toHttpRequestBuilder
-
proceed
Forward this request to a target URL and return the response. Mirrorskarate.proceed()so JS-file mocks can implement proxy behavior. IftargetUrlis null, uses theHostheader on this request. -
jsGet
- Specified by:
jsGetin interfaceio.karatelabs.js.SimpleObject
-