mirror of
https://github.com/androidx/media.git
synced 2025-05-10 00:59:51 +08:00
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
This commit is contained in:
parent
924a76d532
commit
3196bc40db
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user