Class CronetDataSource.Factory

    • Constructor Detail

      • Factory

        public Factory​(org.chromium.net.CronetEngine cronetEngine,
                       Executor executor)
        Creates an instance.
        Parameters:
        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 - The 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.
    • Method Detail

      • setDefaultRequestProperties

        @CanIgnoreReturnValue
        public final CronetDataSource.Factory setDefaultRequestProperties​(Map<String,​String> defaultRequestProperties)
        Description copied from interface: HttpDataSource.Factory
        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.

        Specified by:
        setDefaultRequestProperties in interface HttpDataSource.Factory
        Parameters:
        defaultRequestProperties - The default request properties.
        Returns:
        This factory.
      • setUserAgent

        @CanIgnoreReturnValue
        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 CronetEngine to be used.

        Parameters:
        userAgent - The user agent that will be used, or null to use the default user agent of the underlying CronetEngine.
        Returns:
        This factory.
      • setRequestPriority

        @CanIgnoreReturnValue
        public CronetDataSource.Factory setRequestPriority​(int requestPriority)
        Sets the priority of requests made by CronetDataSource instances created by this factory.

        The default is UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM.

        Parameters:
        requestPriority - The request priority, which should be one of Cronet's UrlRequest.Builder#REQUEST_PRIORITY_* constants.
        Returns:
        This factory.
      • setResetTimeoutOnRedirects

        @CanIgnoreReturnValue
        public CronetDataSource.Factory setResetTimeoutOnRedirects​(boolean resetTimeoutOnRedirects)
        Sets whether the connect timeout is reset when a redirect occurs.

        The default is false.

        Parameters:
        resetTimeoutOnRedirects - Whether the connect timeout is reset when a redirect occurs.
        Returns:
        This factory.
      • setHandleSetCookieRequests

        @CanIgnoreReturnValue
        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:
        handleSetCookieRequests - Whether "Set-Cookie" requests on redirect should be forwarded to the redirect url in the "Cookie" header.
        Returns:
        This factory.
      • setKeepPostFor302Redirects

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