mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
parent
8c5703e931
commit
70ccbc6eb8
4 changed files with 20 additions and 10 deletions
|
|
@ -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.getHttpStatusText(), 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,8 +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.getHttpStatusText(),
|
new InvalidResponseCodeException(
|
||||||
info.getAllHeaders(), currentDataSpec);
|
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, response.message(), 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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -298,14 +298,16 @@ public interface HttpDataSource extends DataSource {
|
||||||
/**
|
/**
|
||||||
* The HTTP status message.
|
* The HTTP status message.
|
||||||
*/
|
*/
|
||||||
public final @Nullable String responseMessage;
|
@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, @Nullable String responseMessage,
|
public InvalidResponseCodeException(
|
||||||
|
int responseCode,
|
||||||
|
@Nullable String responseMessage,
|
||||||
Map<String, List<String>> headerFields,
|
Map<String, List<String>> headerFields,
|
||||||
DataSpec dataSpec) {
|
DataSpec dataSpec) {
|
||||||
super("Response code: " + responseCode, dataSpec, TYPE_OPEN);
|
super("Response code: " + responseCode, dataSpec, TYPE_OPEN);
|
||||||
|
|
|
||||||
|
|
@ -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, "Internal Server Error", 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…
Reference in a new issue