# WebResourceResponseCompat

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [View Source](https://cs.android.com/search?q=file:androidx/webkit/WebResourceResponseCompat.java+class:androidx.webkit.WebResourceResponseCompat) Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

*** ** * ** ***


```
class WebResourceResponseCompat
```

<br />

*** ** * ** ***

Compatibility version of `https://developer.android.com/reference/android/webkit/WebResourceResponse.html`. This class can be used as a direct replacement of the framework class.

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` |   |

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#WebResourceResponseCompat(java.lang.String,java.lang.String,java.io.InputStream)( mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, data: https://developer.android.com/reference/java/io/InputStream.html? )` Constructor matching `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#WebResourceResponse(java.lang.String, java.lang.String, java.io.InputStream)` |
| `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#WebResourceResponseCompat(java.lang.String,java.lang.String,int,java.lang.String,java.util.Map<java.lang.String,java.lang.String>,java.io.InputStream)( mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, statusCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, reasonPhrase: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, responseHeaders: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>?, data: https://developer.android.com/reference/java/io/InputStream.html? )` Constructor matching `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#WebResourceResponse(java.lang.String, java.lang.String, int, java.lang.String, java.util.Map&lt;java.lang.String,java.lang.String&gt;, java.io.InputStream)` |

| ### Public functions |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#getCookies()()` Get the list of cookies set by `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setCookies(java.util.List<java.lang.String>)` or an empty list. |
| `https://developer.android.com/reference/java/io/InputStream.html?` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#getData()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#getEncoding()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#getMimeType()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#getReasonPhrase()()` |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#getResponseHeaders()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#getStatusCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setCookies(java.util.List<java.lang.String>)(cookies: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>)` Set the list of `Set-Cookie` header values applicable to this response. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setData(java.io.InputStream)(data: https://developer.android.com/reference/java/io/InputStream.html?)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setEncoding(java.lang.String)(encoding: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setMimeType(java.lang.String)(mimeType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setResponseHeaders(java.util.Map<java.lang.String,java.lang.String>)(headers: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setStatusCodeAndReasonPhrase(int,java.lang.String)(statusCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, reasonPhrase: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` |
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#toWebResourceResponse()()` Convert this object to a `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` that can be used as return value in `https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldInterceptRequest(android.webkit.WebView, android.webkit.WebResourceRequest)` and `https://developer.android.com/reference/android/webkit/ServiceWorkerClient.html#shouldInterceptRequest(android.webkit.WebResourceRequest)`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat` | `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#toWebResourceResponseCompat(android.webkit.WebResourceResponse)(response: https://developer.android.com/reference/android/webkit/WebResourceResponse.html)` Convert a `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` to the compat version. |

## Public constructors

### WebResourceResponseCompat

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
WebResourceResponseCompat(
    mimeType: String,
    encoding: String?,
    data: InputStream?
)
```

Constructor matching `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#WebResourceResponse(java.lang.String, java.lang.String, java.io.InputStream)`

### WebResourceResponseCompat

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
WebResourceResponseCompat(
    mimeType: String,
    encoding: String?,
    statusCode: Int,
    reasonPhrase: String,
    responseHeaders: (Mutable)Map<String!, String!>?,
    data: InputStream?
)
```

Constructor matching `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#WebResourceResponse(java.lang.String, java.lang.String, int, java.lang.String, java.util.Map&lt;java.lang.String,java.lang.String&gt;, java.io.InputStream)`

## Public functions

### getCookies

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun getCookies(): (Mutable)List<String!>
```

Get the list of cookies set by `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setCookies(java.util.List<java.lang.String>)` or an empty list.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#COOKIE_INTERCEPT()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### getData

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun getData(): InputStream?
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#getData()` |   |

### getEncoding

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun getEncoding(): String?
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#getEncoding()` |   |

### getMimeType

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun getMimeType(): String
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#getMimeType()` |   |

### getReasonPhrase

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun getReasonPhrase(): String?
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#getReasonPhrase()` |   |

### getResponseHeaders

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun getResponseHeaders(): (Mutable)Map<String!, String!>
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#getResponseHeaders()` |   |

### getStatusCode

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun getStatusCode(): Int
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#getStatusCode()` |   |

### setCookies

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
fun setCookies(cookies: (Mutable)List<String!>): Unit
```

Set the list of `Set-Cookie` header values applicable to this response.

Note that these values will only be used by WebView if `https://developer.android.com/reference/kotlin/androidx/webkit/WebSettingsCompat#areCookiesIncludedInShouldInterceptRequest(android.webkit.WebSettings)` is `true`, and by service workers if `https://developer.android.com/reference/kotlin/androidx/webkit/ServiceWorkerWebSettingsCompat#isIncludeCookiesOnShouldInterceptRequestEnabled()` is `true`. Otherwise the values will be ignored.

It is safe to use this method even if the map of response headers provided in the constructor or through `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setResponseHeaders(java.util.Map<java.lang.String,java.lang.String>)` already contains a `Set-Cookie` value. In such cases, all values will be applied. However, it is recommended to only use this method to supply `Set-Cookie` header values. A `Set-Cookie` value in the header map will also only be used according to the restrictions mentioned above.

| Parameters |
|---|---|
| `cookies: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` | List of valid `Set-Cookie` header values |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#COOKIE_INTERCEPT()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### setData

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun setData(data: InputStream?): Unit
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#setData(java.io.InputStream)` |   |

### setEncoding

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun setEncoding(encoding: String?): Unit
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#setEncoding(java.lang.String)` |   |

### setMimeType

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun setMimeType(mimeType: String): Unit
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#setMimeType(java.lang.String)` |   |

### setResponseHeaders

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun setResponseHeaders(headers: (Mutable)Map<String!, String!>): Unit
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#setResponseHeaders(java.util.Map&lt;java.lang.String,java.lang.String&gt;)` |   |

### setStatusCodeAndReasonPhrase

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun setStatusCodeAndReasonPhrase(statusCode: Int, reasonPhrase: String): Unit
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#setStatusCodeAndReasonPhrase(int, java.lang.String)` |   |

### toWebResourceResponse

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
fun toWebResourceResponse(): WebResourceResponse
```

Convert this object to a `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` that can be used as return value in `https://developer.android.com/reference/android/webkit/WebViewClient.html#shouldInterceptRequest(android.webkit.WebView, android.webkit.WebResourceRequest)` and `https://developer.android.com/reference/android/webkit/ServiceWorkerClient.html#shouldInterceptRequest(android.webkit.WebResourceRequest)`.

The cookie headers set through `https://developer.android.com/reference/kotlin/androidx/webkit/WebResourceResponseCompat#setCookies(java.util.List<java.lang.String>)` will be encoded as part of the `https://developer.android.com/reference/android/webkit/WebResourceResponse.html#getResponseHeaders()` header map to use by the WebView implementation.

### toWebResourceResponseCompat

Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.15.0)

```
java-static fun toWebResourceResponseCompat(response: WebResourceResponse): WebResourceResponseCompat
```

Convert a `https://developer.android.com/reference/android/webkit/WebResourceResponse.html` to the compat version.