WebResourceResponseCompat


public class WebResourceResponseCompat


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

Summary

Public constructors

WebResourceResponseCompat(
    @NonNull String mimeType,
    @Nullable String encoding,
    @Nullable InputStream data
)

Constructor matching WebResourceResponse

WebResourceResponseCompat(
    @NonNull String mimeType,
    @Nullable String encoding,
    int statusCode,
    @NonNull String reasonPhrase,
    @Nullable Map<StringString> responseHeaders,
    @Nullable InputStream data
)

Constructor matching WebResourceResponse

Public methods

@NonNull 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.

@Nullable InputStream
@Nullable String
@NonNull String
@Nullable String
@NonNull Map<StringString>
int
void
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
setCookies(@NonNull List<String> cookies)

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

void
void
void
void
void
setStatusCodeAndReasonPhrase(
    int statusCode,
    @NonNull String reasonPhrase
)
@NonNull WebResourceResponse

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

static @NonNull WebResourceResponseCompat

Convert a WebResourceResponse to the compat version.

Public constructors

WebResourceResponseCompat

Added in 1.15.0-beta01
public WebResourceResponseCompat(
    @NonNull String mimeType,
    @Nullable String encoding,
    @Nullable InputStream data
)

Constructor matching WebResourceResponse

WebResourceResponseCompat

Added in 1.15.0-beta01
public WebResourceResponseCompat(
    @NonNull String mimeType,
    @Nullable String encoding,
    int statusCode,
    @NonNull String reasonPhrase,
    @Nullable Map<StringString> responseHeaders,
    @Nullable InputStream data
)

Constructor matching WebResourceResponse

Public methods

getCookies

Added in 1.15.0-beta01
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit"
            + ".WebViewFeature#isFeatureSupported")
public @NonNull List<StringgetCookies()

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

getData

Added in 1.15.0-beta01
public @Nullable InputStream getData()
See also
getData

getEncoding

Added in 1.15.0-beta01
public @Nullable String getEncoding()
See also
getEncoding

getMimeType

Added in 1.15.0-beta01
public @NonNull String getMimeType()
See also
getMimeType

getReasonPhrase

Added in 1.15.0-beta01
public @Nullable String getReasonPhrase()
See also
getReasonPhrase

getResponseHeaders

Added in 1.15.0-beta01
public @NonNull Map<StringStringgetResponseHeaders()

getStatusCode

Added in 1.15.0-beta01
public int getStatusCode()
See also
getStatusCode

setCookies

Added in 1.15.0-beta01
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public void setCookies(@NonNull List<String> cookies)

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

Note that these values will only be used by WebView if areCookiesIncludedInShouldInterceptRequest 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
@NonNull List<String> cookies

List of valid Set-Cookie header values

setData

Added in 1.15.0-beta01
public void setData(@Nullable InputStream data)
See also
setData

setEncoding

Added in 1.15.0-beta01
public void setEncoding(@Nullable String encoding)
See also
setEncoding

setMimeType

Added in 1.15.0-beta01
public void setMimeType(@NonNull String mimeType)
See also
setMimeType

setResponseHeaders

Added in 1.15.0-beta01
public void setResponseHeaders(@NonNull Map<StringString> headers)

setStatusCodeAndReasonPhrase

Added in 1.15.0-beta01
public void setStatusCodeAndReasonPhrase(
    int statusCode,
    @NonNull String reasonPhrase
)

toWebResourceResponse

Added in 1.15.0-beta01
public @NonNull WebResourceResponse toWebResourceResponse()

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

Added in 1.15.0-beta01
public static @NonNull WebResourceResponseCompat toWebResourceResponseCompat(@NonNull WebResourceResponse response)

Convert a WebResourceResponse to the compat version.