@@ -290,33 +290,37 @@ private WebResourceResponse handleProxyRequest(WebResourceRequest request, PathH
290
290
final String method = request .getMethod ();
291
291
if (method .equals ("GET" )) {
292
292
try {
293
- String path = request .getUrl ().getPath ();
294
293
String url = request .getUrl ().toString ();
295
294
Map <String , String > headers = request .getRequestHeaders ();
296
- HttpURLConnection conn = ( HttpURLConnection ) new URL ( url ). openConnection () ;
295
+ boolean isHtmlText = false ;
297
296
for (Map .Entry <String , String > header : headers .entrySet ()) {
298
- conn .setRequestProperty (header .getKey (), header .getValue ());
299
- }
300
- String getCookie = CookieManager .getInstance ().getCookie (url );
301
- if (getCookie != null ) {
302
- conn .setRequestProperty ("Cookie" , getCookie );
303
- }
304
- conn .setRequestMethod (method );
305
- conn .setReadTimeout (30 * 1000 );
306
- conn .setConnectTimeout (30 * 1000 );
307
- String cookie = conn .getHeaderField ("Set-Cookie" );
308
- if (cookie != null ) {
309
- CookieManager .getInstance ().setCookie (url , cookie );
297
+ if (header .getKey ().equalsIgnoreCase ("Accept" ) && header .getValue ().toLowerCase ().contains ("text/html" )) {
298
+ isHtmlText = true ;
299
+ break ;
300
+ }
310
301
}
311
-
312
- if (conn .getContentType ().contains ("text/html" )) {
302
+ if (isHtmlText ) {
303
+ HttpURLConnection conn = (HttpURLConnection ) new URL (url ).openConnection ();
304
+ for (Map .Entry <String , String > header : headers .entrySet ()) {
305
+ conn .setRequestProperty (header .getKey (), header .getValue ());
306
+ }
307
+ String getCookie = CookieManager .getInstance ().getCookie (url );
308
+ if (getCookie != null ) {
309
+ conn .setRequestProperty ("Cookie" , getCookie );
310
+ }
311
+ conn .setRequestMethod (method );
312
+ conn .setReadTimeout (30 * 1000 );
313
+ conn .setConnectTimeout (30 * 1000 );
314
+ String cookie = conn .getHeaderField ("Set-Cookie" );
315
+ if (cookie != null ) {
316
+ CookieManager .getInstance ().setCookie (url , cookie );
317
+ }
313
318
InputStream responseStream = conn .getInputStream ();
314
319
responseStream = jsInjector .getInjectedStream (responseStream );
315
320
bridge .reset ();
316
321
return new WebResourceResponse ("text/html" , handler .getEncoding (),
317
322
handler .getStatusCode (), handler .getReasonPhrase (), handler .getResponseHeaders (), responseStream );
318
323
}
319
-
320
324
} catch (SocketTimeoutException ex ) {
321
325
bridge .handleAppUrlLoadError (ex );
322
326
} catch (Exception ex ) {
0 commit comments