diff --git a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java index fd6a3ce9ec..5c6f5dafd9 100644 --- a/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java +++ b/extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java @@ -606,11 +606,9 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { if (request != currentUrlRequest) { return; } - if (currentDataSpec.postBody != null) { + if (currentDataSpec.httpMethod == DataSpec.HTTP_METHOD_POST) { int responseCode = info.getHttpStatusCode(); // The industry standard is to disregard POST redirects when the status code is 307 or 308. - // For other redirect response codes the POST request is converted to a GET request and the - // redirect is followed. if (responseCode == 307 || responseCode == 308) { exception = new InvalidResponseCodeException(responseCode, info.getAllHeaders(), currentDataSpec); @@ -627,7 +625,23 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource { request.followRedirect(); } else { currentUrlRequest.cancel(); - DataSpec redirectUrlDataSpec = currentDataSpec.withUri(Uri.parse(newLocationUrl)); + DataSpec redirectUrlDataSpec; + if (currentDataSpec.httpMethod == DataSpec.HTTP_METHOD_POST) { + // For POST redirects that aren't 307 or 308, the redirect is followed but request is + // transformed into a GET. + redirectUrlDataSpec = + new DataSpec( + Uri.parse(newLocationUrl), + DataSpec.HTTP_METHOD_GET, + /* httpBody= */ null, + currentDataSpec.absoluteStreamPosition, + currentDataSpec.position, + currentDataSpec.length, + currentDataSpec.key, + currentDataSpec.flags); + } else { + redirectUrlDataSpec = currentDataSpec.withUri(Uri.parse(newLocationUrl)); + } UrlRequest.Builder requestBuilder; try { requestBuilder = buildRequestBuilder(redirectUrlDataSpec);