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

Response

data class Response : Closeable (source)

The Response data class represents a reponse 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.
}

Types

Body

class Body : Closeable, AutoCloseable

A Body returned along with the Request.

Constructors

<init>

Response(url: String, status: Int, headers: Headers, body: Body)

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

Properties

body

val body: Body

headers

val headers: Headers

status

val status: Int

url

val url: String

Functions

close

fun close(): Unit

Closes this Response and its Body and releases any system resources associated with it.

Extension Properties

clientError

val Response.clientError: Boolean

Returns true if the response was a client error (status in the range 400-499) or false otherwise.

success

val Response.success: Boolean

Returns true if the response was successful (status in the range 200-299) or false otherwise.