From 3196bc40dbac54bac272cedc4fe42f47f551b88b Mon Sep 17 00:00:00 2001 From: olly Date: Fri, 24 Aug 2018 06:53:31 -0700 Subject: [PATCH] Fix CronetDataSource redirect logic - Remove usage of deprecated postBody field - Transform POST to GET on redirect, as in DefaultHttpDataSource ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=210092576 --- .../ext/cronet/CronetDataSource.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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);