Skip to content

HTTPRequest.Response ​

com.jsmacrosce.jsmacros.core.library.impl.classes.HTTPRequest.Response

Since1.1.8

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 stream
  • responseCode: the status the server answered with
  • headers: the response headers, or null to leave headers unset

Fields ​

headers ​

headers: Map<String, List<String>>#
Response headers as a map from each name to its returned values. This is null when the response was constructed with null headers.

responseCode ​

responseCode: int#
The response status code.

Methods ​

byteArray ​

byteArray(): byte[]Since1.2.2#
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 ​

text(): StringSince1.1.8#
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