Skip to content

Commit

Permalink
fix(android): Make proxy handle user info in server url (#4699)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Jun 8, 2021
1 parent 04e589e commit baeed45
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.content.Context;
import android.net.Uri;
import android.util.Base64;
import android.webkit.CookieManager;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
Expand All @@ -26,6 +27,7 @@
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -343,6 +345,11 @@ private WebResourceResponse handleProxyRequest(WebResourceRequest request, PathH
conn.setRequestMethod(method);
conn.setReadTimeout(30 * 1000);
conn.setConnectTimeout(30 * 1000);
if (request.getUrl().getUserInfo() != null) {
byte[] userInfoBytes = request.getUrl().getUserInfo().getBytes(StandardCharsets.UTF_8);
String base64 = Base64.encodeToString(userInfoBytes, Base64.NO_WRAP);
conn.setRequestProperty("Authorization", "Basic " + base64);
}
String cookie = conn.getHeaderField("Set-Cookie");
if (cookie != null) {
CookieManager.getInstance().setCookie(url, cookie);
Expand Down

0 comments on commit baeed45

Please sign in to comment.