Followup: Apply the User-Agent header correctly to Android WebView

Summary:
Followup for #5822, addressing nits.

**Test Plan**

Travis CI (the author of #5822 tested the change).
Closes https://github.com/facebook/react-native/pull/10563

Differential Revision: D4081826

fbshipit-source-id: f3a2e1996bf02f81fecea6e53fe1c522b8c85689
This commit is contained in:
Martin Konicek 2016-10-26 10:01:47 -07:00 committed by Facebook Github Bot
parent dc02907039
commit b28c0bb7db
1 changed files with 8 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import javax.annotation.Nullable;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import android.content.Intent; import android.content.Intent;
@ -428,7 +429,13 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
ReadableMapKeySetIterator iter = headers.keySetIterator(); ReadableMapKeySetIterator iter = headers.keySetIterator();
while (iter.hasNextKey()) { while (iter.hasNextKey()) {
String key = iter.nextKey(); String key = iter.nextKey();
headerMap.put(key, headers.getString(key)); if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
if (view.getSettings() != null) {
view.getSettings().setUserAgentString(headers.getString(key));
}
} else {
headerMap.put(key, headers.getString(key));
}
} }
} }
view.loadUrl(url, headerMap); view.loadUrl(url, headerMap);