Commit 1a4b1e1e by christosts Committed by Oliver Woodman

Revert "Add HTTP request parameters (headers) to DataSpec."

This reverts commit c3d6be3a.
parent 26e29307
...@@ -24,9 +24,6 @@ import java.lang.annotation.Documented; ...@@ -24,9 +24,6 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/** /**
* Defines a region of data. * Defines a region of data.
...@@ -105,10 +102,9 @@ public final class DataSpec { ...@@ -105,10 +102,9 @@ public final class DataSpec {
/** @deprecated Use {@link #httpBody} instead. */ /** @deprecated Use {@link #httpBody} instead. */
@Deprecated public final @Nullable byte[] postBody; @Deprecated public final @Nullable byte[] postBody;
/** Immutable map containing the headers to use in HTTP requests. */ /**
public final Map<String, String> httpRequestHeaders; * The absolute position of the data in the full stream.
*/
/** The absolute position of the data in the full stream. */
public final long absoluteStreamPosition; public final long absoluteStreamPosition;
/** /**
* The position of the data when read from {@link #uri}. * The position of the data when read from {@link #uri}.
...@@ -239,6 +235,7 @@ public final class DataSpec { ...@@ -239,6 +235,7 @@ public final class DataSpec {
* @param key {@link #key}. * @param key {@link #key}.
* @param flags {@link #flags}. * @param flags {@link #flags}.
*/ */
@SuppressWarnings("deprecation")
public DataSpec( public DataSpec(
Uri uri, Uri uri,
@HttpMethod int httpMethod, @HttpMethod int httpMethod,
...@@ -248,41 +245,6 @@ public final class DataSpec { ...@@ -248,41 +245,6 @@ public final class DataSpec {
long length, long length,
@Nullable String key, @Nullable String key,
@Flags int flags) { @Flags int flags) {
this(
uri,
httpMethod,
httpBody,
absoluteStreamPosition,
position,
length,
key,
flags,
/* httpRequestHeaders= */ Collections.emptyMap());
}
/**
* Construct a data spec with request parameters to be used as HTTP headers inside HTTP requests.
*
* @param uri {@link #uri}.
* @param httpMethod {@link #httpMethod}.
* @param httpBody {@link #httpBody}.
* @param absoluteStreamPosition {@link #absoluteStreamPosition}.
* @param position {@link #position}.
* @param length {@link #length}.
* @param key {@link #key}.
* @param flags {@link #flags}.
* @param httpRequestHeaders {@link #httpRequestHeaders}.
*/
public DataSpec(
Uri uri,
@HttpMethod int httpMethod,
@Nullable byte[] httpBody,
long absoluteStreamPosition,
long position,
long length,
@Nullable String key,
@Flags int flags,
Map<String, String> httpRequestHeaders) {
Assertions.checkArgument(absoluteStreamPosition >= 0); Assertions.checkArgument(absoluteStreamPosition >= 0);
Assertions.checkArgument(position >= 0); Assertions.checkArgument(position >= 0);
Assertions.checkArgument(length > 0 || length == C.LENGTH_UNSET); Assertions.checkArgument(length > 0 || length == C.LENGTH_UNSET);
...@@ -295,7 +257,6 @@ public final class DataSpec { ...@@ -295,7 +257,6 @@ public final class DataSpec {
this.length = length; this.length = length;
this.key = key; this.key = key;
this.flags = flags; this.flags = flags;
this.httpRequestHeaders = Collections.unmodifiableMap(new HashMap<>(httpRequestHeaders));
} }
/** /**
...@@ -383,8 +344,7 @@ public final class DataSpec { ...@@ -383,8 +344,7 @@ public final class DataSpec {
position + offset, position + offset,
length, length,
key, key,
flags, flags);
httpRequestHeaders);
} }
} }
...@@ -396,14 +356,6 @@ public final class DataSpec { ...@@ -396,14 +356,6 @@ public final class DataSpec {
*/ */
public DataSpec withUri(Uri uri) { public DataSpec withUri(Uri uri) {
return new DataSpec( return new DataSpec(
uri, uri, httpMethod, httpBody, absoluteStreamPosition, position, length, key, flags);
httpMethod,
httpBody,
absoluteStreamPosition,
position,
length,
key,
flags,
httpRequestHeaders);
} }
} }
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.upstream;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.fail;
import android.net.Uri;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Unit tests for {@link DataSpec}. */
@RunWith(AndroidJUnit4.class)
public class DataSpecTest {
@Test
public void createDataSpec_withDefaultValues_setsEmptyHttpRequestParameters() {
Uri uri = Uri.parse("www.google.com");
DataSpec dataSpec = new DataSpec(uri);
assertThat(dataSpec.httpRequestHeaders.isEmpty()).isTrue();
dataSpec = new DataSpec(uri, /*flags= */ 0);
assertThat(dataSpec.httpRequestHeaders.isEmpty()).isTrue();
dataSpec =
new DataSpec(
uri,
/* httpMethod= */ 0,
/* httpBody= */ new byte[] {0, 0, 0, 0},
/* absoluteStreamPosition= */ 0,
/* position= */ 0,
/* length= */ 1,
/* key= */ "key",
/* flags= */ 0);
assertThat(dataSpec.httpRequestHeaders.isEmpty()).isTrue();
}
@Test
public void createDataSpec_setsHttpRequestParameters() {
Map<String, String> httpRequestParameters = new HashMap<>();
httpRequestParameters.put("key1", "value1");
httpRequestParameters.put("key2", "value2");
httpRequestParameters.put("key3", "value3");
DataSpec dataSpec =
new DataSpec(
Uri.parse("www.google.com"),
/* httpMethod= */ 0,
/* httpBody= */ new byte[] {0, 0, 0, 0},
/* absoluteStreamPosition= */ 0,
/* position= */ 0,
/* length= */ 1,
/* key= */ "key",
/* flags= */ 0,
httpRequestParameters);
assertThat(dataSpec.httpRequestHeaders).isEqualTo(httpRequestParameters);
}
@Test
public void httpRequestParameters_areReadOnly() {
DataSpec dataSpec =
new DataSpec(
Uri.parse("www.google.com"),
/* httpMethod= */ 0,
/* httpBody= */ new byte[] {0, 0, 0, 0},
/* absoluteStreamPosition= */ 0,
/* position= */ 0,
/* length= */ 1,
/* key= */ "key",
/* flags= */ 0,
/* httpRequestHeaders= */ new HashMap<>());
try {
dataSpec.httpRequestHeaders.put("key", "value");
fail();
} catch (UnsupportedOperationException expected) {
// Expected
}
}
@Test
public void copyMethods_copiesHttpRequestHeaders() {
Map<String, String> httpRequestParameters = new HashMap<>();
httpRequestParameters.put("key1", "value1");
httpRequestParameters.put("key2", "value2");
httpRequestParameters.put("key3", "value3");
DataSpec dataSpec =
new DataSpec(
Uri.parse("www.google.com"),
/* httpMethod= */ 0,
/* httpBody= */ new byte[] {0, 0, 0, 0},
/* absoluteStreamPosition= */ 0,
/* position= */ 0,
/* length= */ 1,
/* key= */ "key",
/* flags= */ 0,
httpRequestParameters);
DataSpec dataSpecCopy = dataSpec.withUri(Uri.parse("www.new-uri.com"));
assertThat(dataSpecCopy.httpRequestHeaders).isEqualTo(httpRequestParameters);
dataSpecCopy = dataSpec.subrange(2);
assertThat(dataSpecCopy.httpRequestHeaders).isEqualTo(httpRequestParameters);
dataSpecCopy = dataSpec.subrange(2, 2);
assertThat(dataSpecCopy.httpRequestHeaders).isEqualTo(httpRequestParameters);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment