HTTPRequest.Response
com.jsmacrosce.jsmacros.core.library.impl.classes.HTTPRequest.Response
Holds a response status and headers plus its unread body stream. Sending methods return responses for HTTP error statuses as well as successful statuses. The body is consumed by text() or byteArray(); whichever reads first leaves no data for the other.
Nested type declared in HTTPRequest.
Constructors
new HTTPRequest.Response
new HTTPRequest.Response(InputStream inputStream, int responseCode, Map<String, List<String>> headers)#Wraps a body stream, status code, and optional response headers.
Parameters:
inputStream: the body streamresponseCode: the status the server answered withheaders: the response headers, ornullto leave headers unset
Fields
headers
responseCode
responseCode: int#The response status code.
Methods
byteArray
Reads the response body as raw bytes, without decoding. This consumes the body stream; if text() was called first, this returns an empty array.
// saving a download beside the script that fetched it
const response = Request.get("https://example.com/assets/logo.png");
if (response.responseCode === 200) {
FS.open("assets/logo.png").write(response.byteArray());
}Returns: the body, or an empty array for an empty one
text
Reads the response body as UTF-8 text, ignoring any charset named in the response headers. Line terminators are removed and remaining lines are joined with
\n. The result is cached for subsequent calls. Reading consumes the body stream, so calling byteArray() afterward returns no bytes.Returns: the body, or an empty string for an empty one