WebResourceResponseCompat


class WebResourceResponseCompat


Compatibility version of WebResourceResponse. This class can be used as a direct replacement of the framework class.

Summary

Public constructors

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

Constructor matching WebResourceResponse

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

Constructor matching WebResourceResponse

Public functions

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

Get the list of cookies set by setCookies or an empty list.

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

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

Unit
Unit
setEncoding(encoding: String?)
Unit
setMimeType(mimeType: String)
Unit
Unit
setStatusCodeAndReasonPhrase(statusCode: Int, reasonPhrase: String)
WebResourceResponse

Convert this object to a WebResourceResponse that can be used as return value in shouldInterceptRequest and shouldInterceptRequest.

java-static WebResourceResponseCompat

Convert a WebResourceResponse to the compat version.

Public constructors

WebResourceResponseCompat

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

Constructor matching WebResourceResponse

WebResourceResponseCompat

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

Constructor matching WebResourceResponse

Public functions

getCookies

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

Get the list of cookies set by setCookies or an empty list.

getData

fun getData(): InputStream?
See also
getData

getEncoding

fun getEncoding(): String?
See also
getEncoding

getMimeType

fun getMimeType(): String
See also
getMimeType

getReasonPhrase

fun getReasonPhrase(): String?
See also
getReasonPhrase

getResponseHeaders

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

getStatusCode

fun getStatusCode(): Int
See also
getStatusCode

setCookies

@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 isIncludeCookiesOnShouldInterceptRequestEnabled is true, and by service workers if 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 setResponseHeaders 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.

This method should only be called if isFeatureSupported returns true for COOKIE_INTERCEPT.

Parameters
cookies: (Mutable)List<String!>

List of valid Set-Cookie header values

setData

fun setData(data: InputStream?): Unit
See also
setData

setEncoding

fun setEncoding(encoding: String?): Unit
See also
setEncoding

setMimeType

fun setMimeType(mimeType: String): Unit
See also
setMimeType

setResponseHeaders

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

setStatusCodeAndReasonPhrase

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

toWebResourceResponse

fun toWebResourceResponse(): WebResourceResponse

Convert this object to a WebResourceResponse that can be used as return value in shouldInterceptRequest and shouldInterceptRequest.

The cookie headers set through setCookies will be encoded as part of the getResponseHeaders header map to use by the WebView implementation.

toWebResourceResponseCompat

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

Convert a WebResourceResponse to the compat version.