Skip to content

Commit

Permalink
Add some convenience constructors for Cronet in V2
Browse files Browse the repository at this point in the history
- The need to pass a Clock is pretty much only for testing, so
  make the constructor that takes one package private + use
  the system clock for public constructors.
- Add default timeout values.
- Also make sure we set Content-Type in all license requests,
  since when using Cronet the stack requires it to be set.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131404298
  • Loading branch information
ojw28 committed Aug 31, 2016
1 parent 4f670ad commit f8311a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public byte[] executeKeyRequest(UUID uuid, KeyRequest request) throws Exception
private byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
throws IOException {
HttpDataSource dataSource = dataSourceFactory.createDataSource();
// Note: This will be overridden by a Content-Type in requestProperties, if one is set.
dataSource.setRequestProperty("Content-Type", "application/octet-stream");
if (requestProperties != null) {
for (Map.Entry<String, String> requestProperty : requestProperties.entrySet()) {
dataSource.setRequestProperty(requestProperty.getKey(), requestProperty.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public DefaultDataSourceFactory(Context context, String userAgent,
*/
public DefaultDataSourceFactory(Context context, String userAgent,
TransferListener<? super DataSource> listener, boolean allowCrossProtocolRedirects) {
this(context, userAgent, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS,
DEFAULT_CONNECT_TIMEOUT_MILLIS, allowCrossProtocolRedirects);
this(context, userAgent, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS,
allowCrossProtocolRedirects);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ public class DefaultHttpDataSource implements HttpDataSource {

/**
* @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is
* thrown from {@link #open(DataSpec)}.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* {@link #open(DataSpec)}.
*/
public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePredicate) {
this(userAgent, contentTypePredicate, null);
}

/**
* @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is
* thrown from {@link #open(DataSpec)}.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* {@link #open(DataSpec)}.
* @param listener An optional listener.
*/
public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePredicate,
Expand All @@ -109,9 +109,9 @@ public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePred

/**
* @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is
* thrown from {@link #open(DataSpec)}.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* {@link #open(DataSpec)}.
* @param listener An optional listener.
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
* interpreted as an infinite timeout.
Expand All @@ -126,9 +126,9 @@ public DefaultHttpDataSource(String userAgent, Predicate<String> contentTypePred

/**
* @param userAgent The User-Agent string that should be used.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is
* rejected by the predicate then a {@link HttpDataSource.InvalidContentTypeException} is
* thrown from {@link #open(DataSpec)}.
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from
* {@link #open(DataSpec)}.
* @param listener An optional listener.
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
* interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use
Expand Down

0 comments on commit f8311a4

Please sign in to comment.