Browse Source

fix(android): add Referer header for url redirect load

Roc Wu 4 years ago
parent
commit
85d0c081b2

+ 8
- 1
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

@@ -107,6 +107,7 @@ import javax.annotation.Nullable;
107 107
 public class RNCWebViewManager extends SimpleViewManager<WebView> {
108 108
 
109 109
   public static String activeUrl = null;
110
+  public static String refererUrl = null;
110 111
   public static final int COMMAND_GO_BACK = 1;
111 112
   public static final int COMMAND_GO_FORWARD = 2;
112 113
   public static final int COMMAND_RELOAD = 3;
@@ -609,7 +610,12 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
609 610
         if (args == null) {
610 611
           throw new RuntimeException("Arguments for loading an url are null!");
611 612
         }
612
-        root.loadUrl(args.getString(0));
613
+        HashMap<String, String> headerMap = new HashMap<>();
614
+        if (refererUrl != null) {
615
+          headerMap.put("Referer", refererUrl);
616
+        }
617
+
618
+        root.loadUrl(args.getString(0), headerMap);
613 619
         break;
614 620
       case COMMAND_FOCUS:
615 621
         root.requestFocus();
@@ -742,6 +748,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
742 748
 
743 749
     @Override
744 750
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
751
+      refererUrl = activeUrl;
745 752
       activeUrl = url;
746 753
       dispatchEvent(
747 754
         view,