HttpEngineDataSource.Factory


public final class HttpEngineDataSource.Factory implements HttpDataSource.Factory


DataSource.Factory for HttpEngineDataSource instances.

Summary

Public constructors

Factory(HttpEngine httpEngine, Executor executor)

Creates an instance.

Public methods

HttpDataSource

Creates a DataSource instance.

HttpEngineDataSource.Factory

Sets the connect timeout, in milliseconds.

HttpEngineDataSource.Factory

Sets a content type Predicate.

final HttpEngineDataSource.Factory

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

HttpEngineDataSource.Factory

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

HttpEngineDataSource.Factory

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

HttpEngineDataSource.Factory

Sets the read timeout, in milliseconds.

HttpEngineDataSource.Factory

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

HttpEngineDataSource.Factory

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

HttpEngineDataSource.Factory

Sets the TransferListener that will be used.

HttpEngineDataSource.Factory

Sets the user agent that will be used.

Public constructors

Factory

public Factory(HttpEngine httpEngine, Executor executor)

Creates an instance.

Parameters
HttpEngine httpEngine

An HttpEngine to make the requests.

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 HttpEngine'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 HttpEngineDataSource.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
HttpEngineDataSource.Factory

This factory.

setContentTypePredicate

@CanIgnoreReturnValue
@UnstableApi
public HttpEngineDataSource.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
HttpEngineDataSource.Factory

This factory.

setDefaultRequestProperties

@CanIgnoreReturnValue
@UnstableApi
public final HttpEngineDataSource.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
HttpEngineDataSource.Factory

This factory.

setHandleSetCookieRequests

@CanIgnoreReturnValue
@UnstableApi
public HttpEngineDataSource.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
HttpEngineDataSource.Factory

This factory.

setKeepPostFor302Redirects

@CanIgnoreReturnValue
@UnstableApi
public HttpEngineDataSource.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 HttpEngineDataSource.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
HttpEngineDataSource.Factory

This factory.

setRequestPriority

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

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

The default is REQUEST_PRIORITY_MEDIUM.

Parameters
int requestPriority

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

Returns
HttpEngineDataSource.Factory

This factory.

setResetTimeoutOnRedirects

@CanIgnoreReturnValue
@UnstableApi
public HttpEngineDataSource.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
HttpEngineDataSource.Factory

This factory.

setTransferListener

@CanIgnoreReturnValue
@UnstableApi
public HttpEngineDataSource.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
HttpEngineDataSource.Factory

This factory.

setUserAgent

@CanIgnoreReturnValue
@UnstableApi
public HttpEngineDataSource.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 HttpEngine.

Returns
HttpEngineDataSource.Factory

This factory.