new HttpResponse()
This class allows users to access specific information on HTTP responses.
Methods
getContentBuffer() → {Buffer}
Return the data inside this object as a Buffer.
Example
// The code below logs the value of the first byte of the ioBuster home page.
const response = utility.fetchUrl("https://iobuster.com/");
logger.info(response.getContentBuffer()[0]);
Returns:
the content as a raw binary Buffer
- Type
- Buffer
getContentText() → {String}
Gets the content of an HTTP response encoded as a string.
Example
// The code below logs the HTML code of the ioBuster home page.
const response = utility.fetchUrl("https://iobuster.com/")
logger.info(response.getContentText())
Returns:
the content of the HTTP response, as a string
- Type
- String
getHeaders() → {Object}
Returns an attribute/value map of headers for the HTTP response.
Example
// The code below logs the HTTP headers from the response
// received when fetching the ioBuster home page.
const response = utility.fetchUrl("https://iobuster.com/")
logger.info(response.getHeaders())
Returns:
a JavaScript key/value map of HTTP headers
- Type
- Object
getStatusCode() → {Number}
Get the HTTP status status code (200 for OK, etc.) of an HTTP response.
For all HTTP status codes, please see HTTP status code docs from mozilla.org.
Example
// The code below logs the HTTP status code from the response received
// when fetching the ioBuster home page.
// It should be 200 if the request succeeded.
const response = utility.fetchUrl("https://iobuster.com/")
logger.info(response.getStatusCode())
Returns:
HTTP response status code (e.g. 200 for OK)
- Type
- Number