CronetDataSource.Factory


public final class CronetDataSource.Factory implements HttpDataSource.Factory


DataSource.Factory for CronetDataSource instances.

Summary

Public constructors

Factory(CronetEngine cronetEngine, Executor executor)

Creates an instance.

@UnstableApi
Factory(CronetEngineWrapper cronetEngineWrapper, Executor executor)

This method is deprecated.

Use Factory with an instantiated , or DefaultHttpDataSource for cases where getCronetEngine would have returned null.

Public methods

HttpDataSource

Creates a DataSource instance.

CronetDataSource.Factory

Sets the connect timeout, in milliseconds.

CronetDataSource.Factory

Sets a content type Predicate.

final CronetDataSource.Factory

Sets the default request headers for HttpDataSource instances created by the factory.

CronetDataSource.Factory

This method is deprecated.

Do not use CronetDataSource or its factory in cases where a suitable CronetEngine is not available.

CronetDataSource.Factory

Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

CronetDataSource.Factory

Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.

CronetDataSource.Factory

Sets the read timeout, in milliseconds.

CronetDataSource.Factory

Sets the priority of requests made by CronetDataSource instances created by this factory.

CronetDataSource.Factory

Sets whether the connect timeout is reset when a redirect occurs.

CronetDataSource.Factory

Sets the TransferListener that will be used.

CronetDataSource.Factory

Sets the user agent that will be used.

Public constructors

Factory

public Factory(CronetEngine cronetEngine, Executor executor)

Creates an instance.

Parameters
CronetEngine cronetEngine

A CronetEngine to make the requests. This should not be a fallback instance obtained from JavaCronetProvider. It's more efficient to use DefaultHttpDataSource instead in this case.

Executor executor

The java.util.concurrent.Executor that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from Cronet's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor.

Factory

@UnstableApi
public Factory(CronetEngineWrapper cronetEngineWrapper, Executor executor)

Creates an instance.

Parameters
CronetEngineWrapper cronetEngineWrapper

A CronetEngineWrapper.

Executor executor

The java.util.concurrent.Executor that will handle responses. This may be a direct executor (i.e. executes tasks on the calling thread) in order to avoid a thread hop from Cronet's internal network thread to the response handling thread. However, to avoid slowing down overall network performance, care must be taken to make sure response handling is a fast operation when using a direct executor.

Public methods

createDataSource

@UnstableApi
public HttpDataSource createDataSource()

Creates a DataSource instance.

setConnectionTimeoutMs

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setConnectionTimeoutMs(int connectTimeoutMs)

Sets the connect timeout, in milliseconds.

The default is DEFAULT_CONNECT_TIMEOUT_MILLIS.

Parameters
int connectTimeoutMs

The connect timeout, in milliseconds, that will be used.

Returns
CronetDataSource.Factory

This factory.

setContentTypePredicate

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setContentTypePredicate(
    @Nullable Predicate<String> contentTypePredicate
)

Sets a content type Predicate. If a content type is rejected by the predicate then a HttpDataSource.InvalidContentTypeException is thrown from open.

The default is null.

Parameters
@Nullable Predicate<String> contentTypePredicate

The content type Predicate, or null to clear a predicate that was previously set.

Returns
CronetDataSource.Factory

This factory.

setDefaultRequestProperties

@CanIgnoreReturnValue
@UnstableApi
public final CronetDataSource.Factory setDefaultRequestProperties(
    Map<StringString> defaultRequestProperties
)

Sets the default request headers for HttpDataSource instances created by the factory.

The new request properties will be used for future requests made by HttpDataSources created by the factory, including instances that have already been created. Modifying the defaultRequestProperties map after a call to this method will have no effect, and so it's necessary to call this method again each time the request properties need to be updated.

Parameters
Map<StringString> defaultRequestProperties

The default request properties.

Returns
CronetDataSource.Factory

This factory.

setFallbackFactory

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setFallbackFactory(@Nullable HttpDataSource.Factory fallbackFactory)

Sets the fallback HttpDataSource.Factory that is used as a fallback if the fails to provide a CronetEngine.

By default a DefaultHttpDataSource is used as fallback factory.

Parameters
@Nullable HttpDataSource.Factory fallbackFactory

The fallback factory that will be used.

Returns
CronetDataSource.Factory

This factory.

setHandleSetCookieRequests

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setHandleSetCookieRequests(boolean handleSetCookieRequests)

Sets whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

The default is false.

Parameters
boolean handleSetCookieRequests

Whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.

Returns
CronetDataSource.Factory

This factory.

setKeepPostFor302Redirects

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setKeepPostFor302Redirects(boolean keepPostFor302Redirects)

Sets whether we should keep the POST method and body when we have HTTP 302 redirects for a POST request.

setReadTimeoutMs

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setReadTimeoutMs(int readTimeoutMs)

Sets the read timeout, in milliseconds.

The default is DEFAULT_READ_TIMEOUT_MILLIS.

Parameters
int readTimeoutMs

The connect timeout, in milliseconds, that will be used.

Returns
CronetDataSource.Factory

This factory.

setRequestPriority

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setRequestPriority(int requestPriority)

Sets the priority of requests made by CronetDataSource instances created by this factory.

The default is REQUEST_PRIORITY_MEDIUM.

Parameters
int requestPriority

The request priority, which should be one of Cronet's UrlRequest.Builder#REQUEST_PRIORITY_* constants.

Returns
CronetDataSource.Factory

This factory.

setResetTimeoutOnRedirects

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setResetTimeoutOnRedirects(boolean resetTimeoutOnRedirects)

Sets whether the connect timeout is reset when a redirect occurs.

The default is false.

Parameters
boolean resetTimeoutOnRedirects

Whether the connect timeout is reset when a redirect occurs.

Returns
CronetDataSource.Factory

This factory.

setTransferListener

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setTransferListener(@Nullable TransferListener transferListener)

Sets the TransferListener that will be used.

The default is null.

See addTransferListener.

Parameters
@Nullable TransferListener transferListener

The listener that will be used.

Returns
CronetDataSource.Factory

This factory.

setUserAgent

@CanIgnoreReturnValue
@UnstableApi
public CronetDataSource.Factory setUserAgent(@Nullable String userAgent)

Sets the user agent that will be used.

The default is null, which causes the default user agent of the underlying to be used.

Parameters
@Nullable String userAgent

The user agent that will be used, or null to use the default user agent of the underlying CronetEngine.

Returns
CronetDataSource.Factory

This factory.