android-components / mozilla.components.concept.fetch / Response


data class Response : Closeable (source)

The Response data class represents a response to a Request send by a Client.

You can create a Response object using the constructor, but you are more likely to encounter a Response object being returned as the result of calling Client.fetch.

A Response may hold references to other resources (e.g. streams). Therefore it’s important to always close the Response object or its Body. This can be done by either consuming the content of the Body with one of the available methods or by using Kotlin’s extension methods for using Closeable implementations (like use()):

val response = ...
response.use {
   // Use response. Resources will get released automatically at the end of the block.


Name Summary
Body class Body : Closeable, AutoCloseable
A Body returned along with the Request.


Name Summary
<init> Response(url: String, status: Int, headers: Headers, body: Body)
The Response data class represents a response to a Request send by a Client.


Name Summary
body val body: Body
headers val headers: Headers
status val status: Int
url val url: String


Name Summary
close fun close(): Unit
Closes this Response and its Body and releases any system resources associated with it.

Companion Object Properties

Name Summary

Extension Properties

Name Summary
isClientError val Response.isClientError: Boolean
Returns true if the response was a client error (status in the range 400-499) or false otherwise.
isSuccess val Response.isSuccess: Boolean
Returns true if the response was successful (status in the range 200-299) or false otherwise.

Extension Functions

Name Summary
loadResourceAsString fun Any.loadResourceAsString(path: String): String
Loads a file from the resources folder and returns its content as a string object.