Skip to content

Commit

Permalink
Workaround when proxy returns HTTP_PROXY_AUTH code
Browse files Browse the repository at this point in the history
Force first to connect to http (google.com) and do a second attempt to connect to the original URL.
HTTP_PROXY_AUTH code might be returned when the app tries to connect to https but might work if it has connected first to a http website.
  • Loading branch information
viguice committed Jun 30, 2023
1 parent 1c77445 commit 896f14d
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,19 @@ protected final <T> T runQuery(Parser<T> parser, URL query, String acceptHeader,
}

code = conn instanceof HttpURLConnection ? ((HttpURLConnection) conn).getResponseCode() : HttpURLConnection.HTTP_OK;
if (code == HttpURLConnection.HTTP_PROXY_AUTH)
{
LOGGER.fine("Error with proxy. Second attempt after forcing acces to http website in first place.");
URI uritest= new URI("http://google.com");
URL urltest = uritest.toURL();
conn = urltest.openConnection(proxy);
((HttpURLConnection) conn).setRequestMethod("GET");
code = conn instanceof HttpURLConnection ? ((HttpURLConnection) conn).getResponseCode() : HttpURLConnection.HTTP_OK;
conn = url.openConnection(proxy);
((HttpURLConnection) conn).setRequestMethod("GET");
code = conn instanceof HttpURLConnection ? ((HttpURLConnection) conn).getResponseCode() : HttpURLConnection.HTTP_OK;

}
if (isRedirection(code))
{
URL redirection = getRedirectionURL(conn, code);
Expand Down

0 comments on commit 896f14d

Please sign in to comment.