Fix Widevine L3 provisioning in V2

1. HttpMediaDrmCallback.executeProvisionRequest needs to specify
   an empty byte[], else we do a GET instead of a POST.
2. Content-Type should not be set when making the provision
   request, since there's no body.
3. DataSource implementations must correctly handle a non-null
   body with zero length. CronetDataSource was not handling this
   case. DefaultHttpDataSource was, but made a code modification
   to make it a little clearer. OkHttpDataSource seems to handle
   the case correctly, and it doens't look like the code can be
   made clearer.

Issue #1925

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136042641
This commit is contained in:
olly 2016-10-13 08:23:39 -07:00 committed by Oliver Woodman
parent a22390c29b
commit 6acf59c4fc
3 changed files with 22 additions and 13 deletions

View File

@ -416,8 +416,10 @@ public class CronetDataSource extends UrlRequest.Callback implements HttpDataSou
executor, cronetEngine);
// Set the headers.
synchronized (requestProperties) {
if (dataSpec.postBody != null && !requestProperties.containsKey(CONTENT_TYPE)) {
throw new OpenException("POST request must set Content-Type", dataSpec, Status.IDLE);
if (dataSpec.postBody != null && dataSpec.postBody.length != 0
&& !requestProperties.containsKey(CONTENT_TYPE)) {
throw new OpenException("POST request with non-empty body must set Content-Type", dataSpec,
Status.IDLE);
}
for (Entry<String, String> headerEntry : requestProperties.entrySet()) {
requestBuilder.addHeader(headerEntry.getKey(), headerEntry.getValue());
@ -434,10 +436,13 @@ public class CronetDataSource extends UrlRequest.Callback implements HttpDataSou
}
requestBuilder.addHeader("Range", rangeValue.toString());
}
// Set the body.
// Set the method and (if non-empty) the body.
if (dataSpec.postBody != null) {
requestBuilder.setUploadDataProvider(new ByteArrayUploadDataProvider(dataSpec.postBody),
executor);
requestBuilder.setHttpMethod("POST");
if (dataSpec.postBody.length != 0) {
requestBuilder.setUploadDataProvider(new ByteArrayUploadDataProvider(dataSpec.postBody),
executor);
}
}
return requestBuilder.build();
}

View File

@ -71,7 +71,7 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
@Override
public byte[] executeProvisionRequest(UUID uuid, ProvisionRequest request) throws IOException {
String url = request.getDefaultUrl() + "&signedRequest=" + new String(request.getData());
return executePost(url, null, null);
return executePost(url, new byte[0], null);
}
@Override
@ -81,6 +81,7 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
url = defaultUrl;
}
Map<String, String> requestProperties = new HashMap<>();
requestProperties.put("Content-Type", "application/octet-stream");
if (C.PLAYREADY_UUID.equals(uuid)) {
requestProperties.putAll(PLAYREADY_KEY_REQUEST_PROPERTIES);
}
@ -93,8 +94,6 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
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());

View File

@ -413,11 +413,16 @@ public class DefaultHttpDataSource implements HttpDataSource {
connection.setInstanceFollowRedirects(followRedirects);
connection.setDoOutput(postBody != null);
if (postBody != null) {
connection.setFixedLengthStreamingMode(postBody.length);
connection.connect();
OutputStream os = connection.getOutputStream();
os.write(postBody);
os.close();
connection.setRequestMethod("POST");
if (postBody.length == 0) {
connection.connect();
} else {
connection.setFixedLengthStreamingMode(postBody.length);
connection.connect();
OutputStream os = connection.getOutputStream();
os.write(postBody);
os.close();
}
} else {
connection.connect();
}