From 9b96edc7d557b35f75f1a381798fc10b7e52acb9 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 9 Jun 2020 19:10:23 +0200 Subject: [PATCH] fix(android): set cookie on proxied request (#3076) --- .../main/java/com/getcapacitor/WebViewLocalServer.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java index 9e1ff30fc2..765cd9dedf 100755 --- a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +++ b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java @@ -291,16 +291,20 @@ private WebResourceResponse handleProxyRequest(WebResourceRequest request, PathH if (method.equals("GET")) { try { String path = request.getUrl().getPath(); - URL url = new URL(request.getUrl().toString()); + String url = request.getUrl().toString(); Map headers = request.getRequestHeaders(); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); for (Map.Entry header : headers.entrySet()) { conn.setRequestProperty(header.getKey(), header.getValue()); } - conn.setRequestProperty("Cookie", CookieManager.getInstance().getCookie(request.getUrl().toString())); + conn.setRequestProperty("Cookie", CookieManager.getInstance().getCookie(url)); conn.setRequestMethod(method); conn.setReadTimeout(30 * 1000); conn.setConnectTimeout(30 * 1000); + String cookie = conn.getHeaderField("Set-Cookie"); + if (cookie != null) { + CookieManager.getInstance().setCookie(url, cookie); + } if (conn.getContentType().contains("text/html")) { InputStream responseStream = conn.getInputStream();