Merge pull request #5004 from pakerfeldt/status-message-invalidresponsecodeexception
Provide http status message to InvalidResponseCodeException
This commit is contained in:
commit
3b7d0b7923
@ -326,8 +326,12 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
// Check for a valid response code.
|
// Check for a valid response code.
|
||||||
int responseCode = responseInfo.getHttpStatusCode();
|
int responseCode = responseInfo.getHttpStatusCode();
|
||||||
if (responseCode < 200 || responseCode > 299) {
|
if (responseCode < 200 || responseCode > 299) {
|
||||||
InvalidResponseCodeException exception = new InvalidResponseCodeException(responseCode,
|
InvalidResponseCodeException exception =
|
||||||
responseInfo.getAllHeaders(), currentDataSpec);
|
new InvalidResponseCodeException(
|
||||||
|
responseCode,
|
||||||
|
responseInfo.getHttpStatusText(),
|
||||||
|
responseInfo.getAllHeaders(),
|
||||||
|
currentDataSpec);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
||||||
}
|
}
|
||||||
@ -611,7 +615,11 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
// The industry standard is to disregard POST redirects when the status code is 307 or 308.
|
// The industry standard is to disregard POST redirects when the status code is 307 or 308.
|
||||||
if (responseCode == 307 || responseCode == 308) {
|
if (responseCode == 307 || responseCode == 308) {
|
||||||
exception =
|
exception =
|
||||||
new InvalidResponseCodeException(responseCode, info.getAllHeaders(), currentDataSpec);
|
new InvalidResponseCodeException(
|
||||||
|
responseCode,
|
||||||
|
info.getHttpStatusText(),
|
||||||
|
info.getAllHeaders(),
|
||||||
|
currentDataSpec);
|
||||||
operation.open();
|
operation.open();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -172,8 +172,8 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
Map<String, List<String>> headers = response.headers().toMultimap();
|
Map<String, List<String>> headers = response.headers().toMultimap();
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
InvalidResponseCodeException exception = new InvalidResponseCodeException(
|
InvalidResponseCodeException exception =
|
||||||
responseCode, headers, dataSpec);
|
new InvalidResponseCodeException(responseCode, response.message(), headers, dataSpec);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
||||||
}
|
}
|
||||||
|
@ -283,8 +283,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
}
|
}
|
||||||
|
|
||||||
int responseCode;
|
int responseCode;
|
||||||
|
String responseMessage;
|
||||||
try {
|
try {
|
||||||
responseCode = connection.getResponseCode();
|
responseCode = connection.getResponseCode();
|
||||||
|
responseMessage = connection.getResponseMessage();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
||||||
@ -296,7 +298,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||||||
Map<String, List<String>> headers = connection.getHeaderFields();
|
Map<String, List<String>> headers = connection.getHeaderFields();
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
InvalidResponseCodeException exception =
|
InvalidResponseCodeException exception =
|
||||||
new InvalidResponseCodeException(responseCode, headers, dataSpec);
|
new InvalidResponseCodeException(responseCode, responseMessage, headers, dataSpec);
|
||||||
if (responseCode == 416) {
|
if (responseCode == 416) {
|
||||||
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
exception.initCause(new DataSourceException(DataSourceException.POSITION_OUT_OF_RANGE));
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
import android.support.annotation.IntDef;
|
import android.support.annotation.IntDef;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.google.android.exoplayer2.util.Predicate;
|
import com.google.android.exoplayer2.util.Predicate;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
@ -294,15 +295,24 @@ public interface HttpDataSource extends DataSource {
|
|||||||
*/
|
*/
|
||||||
public final int responseCode;
|
public final int responseCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The HTTP status message.
|
||||||
|
*/
|
||||||
|
@Nullable public final String responseMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An unmodifiable map of the response header fields and values.
|
* An unmodifiable map of the response header fields and values.
|
||||||
*/
|
*/
|
||||||
public final Map<String, List<String>> headerFields;
|
public final Map<String, List<String>> headerFields;
|
||||||
|
|
||||||
public InvalidResponseCodeException(int responseCode, Map<String, List<String>> headerFields,
|
public InvalidResponseCodeException(
|
||||||
|
int responseCode,
|
||||||
|
@Nullable String responseMessage,
|
||||||
|
Map<String, List<String>> headerFields,
|
||||||
DataSpec dataSpec) {
|
DataSpec dataSpec) {
|
||||||
super("Response code: " + responseCode, dataSpec, TYPE_OPEN);
|
super("Response code: " + responseCode, dataSpec, TYPE_OPEN);
|
||||||
this.responseCode = responseCode;
|
this.responseCode = responseCode;
|
||||||
|
this.responseMessage = responseMessage;
|
||||||
this.headerFields = headerFields;
|
this.headerFields = headerFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public final class DefaultLoadErrorHandlingPolicyTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getBlacklistDurationMsFor_blacklist404() {
|
public void getBlacklistDurationMsFor_blacklist404() {
|
||||||
InvalidResponseCodeException exception =
|
InvalidResponseCodeException exception =
|
||||||
new InvalidResponseCodeException(404, Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
new InvalidResponseCodeException(404, "Not Found", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
||||||
assertThat(getDefaultPolicyBlacklistOutputFor(exception))
|
assertThat(getDefaultPolicyBlacklistOutputFor(exception))
|
||||||
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
|
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ public final class DefaultLoadErrorHandlingPolicyTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getBlacklistDurationMsFor_blacklist410() {
|
public void getBlacklistDurationMsFor_blacklist410() {
|
||||||
InvalidResponseCodeException exception =
|
InvalidResponseCodeException exception =
|
||||||
new InvalidResponseCodeException(410, Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
new InvalidResponseCodeException(410, "Gone", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
||||||
assertThat(getDefaultPolicyBlacklistOutputFor(exception))
|
assertThat(getDefaultPolicyBlacklistOutputFor(exception))
|
||||||
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
|
.isEqualTo(DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS);
|
||||||
}
|
}
|
||||||
@ -50,7 +50,8 @@ public final class DefaultLoadErrorHandlingPolicyTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getBlacklistDurationMsFor_dontBlacklistUnexpectedHttpCodes() {
|
public void getBlacklistDurationMsFor_dontBlacklistUnexpectedHttpCodes() {
|
||||||
InvalidResponseCodeException exception =
|
InvalidResponseCodeException exception =
|
||||||
new InvalidResponseCodeException(500, Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
new InvalidResponseCodeException(
|
||||||
|
500, "Internal Server Error", Collections.emptyMap(), new DataSpec(Uri.EMPTY));
|
||||||
assertThat(getDefaultPolicyBlacklistOutputFor(exception)).isEqualTo(C.TIME_UNSET);
|
assertThat(getDefaultPolicyBlacklistOutputFor(exception)).isEqualTo(C.TIME_UNSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user