From d13b34b0c9fe03c22719d353903533c012efc651 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Sat, 15 Aug 2015 11:11:28 -0700 Subject: [PATCH] Fix replacing default user agent on addHeader. Fixes #546. Conflicts: library/src/androidTest/java/com/bumptech/glide/load/model/LazyHeadersTest.java library/src/main/java/com/bumptech/glide/load/model/LazyHeaders.java library/src/test/resources/exif-orientation-examples --- .../bumptech/glide/load/model/LazyHeaders.java | 4 ++-- .../glide/load/model/LazyHeadersTest.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/bumptech/glide/load/model/LazyHeaders.java b/library/src/main/java/com/bumptech/glide/load/model/LazyHeaders.java index 915185fbde..1e4328b9c1 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/LazyHeaders.java +++ b/library/src/main/java/com/bumptech/glide/load/model/LazyHeaders.java @@ -117,9 +117,9 @@ public static final class Builder { } private boolean copyOnModify = true; - private boolean isEncodingDefault = true; private Map> headers = DEFAULT_HEADERS; - private boolean isUserAgentDefault = headers.containsKey(DEFAULT_USER_AGENT); + private boolean isEncodingDefault = true; + private boolean isUserAgentDefault = true; /** * Adds a value for the given header and returns this builder. diff --git a/library/src/test/java/com/bumptech/glide/load/model/LazyHeadersTest.java b/library/src/test/java/com/bumptech/glide/load/model/LazyHeadersTest.java index 8e0269c4e1..04e4151a4c 100644 --- a/library/src/test/java/com/bumptech/glide/load/model/LazyHeadersTest.java +++ b/library/src/test/java/com/bumptech/glide/load/model/LazyHeadersTest.java @@ -8,6 +8,8 @@ import com.bumptech.glide.load.model.LazyHeaders.Builder; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -18,6 +20,22 @@ @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE, sdk = 18) public class LazyHeadersTest { + private static final String DEFAULT_USER_AGENT = "default_user_agent"; + private static final String DEFAULT_USER_AGENT_PROPERTY = "http.agent"; + private String initialUserAgent; + + @Before + public void setUp() { + initialUserAgent = System.getProperty(DEFAULT_USER_AGENT_PROPERTY); + System.setProperty(DEFAULT_USER_AGENT_PROPERTY, DEFAULT_USER_AGENT); + } + + @After + public void tearDown() { + if (initialUserAgent != null) { + System.setProperty(DEFAULT_USER_AGENT_PROPERTY, initialUserAgent); + } + } @Test public void testIncludesEagerHeaders() {