From a7ec3ceee64c69509ab88dd04336c69dc3dd0397 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 18 Jul 2019 17:26:31 +0200 Subject: [PATCH] fix(android): better proxy mimeType detection for Capacitor injection --- .../java/com/getcapacitor/WebViewLocalServer.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java index 907d347da..c0e0c406d 100755 --- a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +++ b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java @@ -302,17 +302,14 @@ private WebResourceResponse handleProxyRequest(WebResourceRequest request, PathH conn.setReadTimeout(30 * 1000); conn.setConnectTimeout(30 * 1000); - InputStream responseStream = conn.getInputStream(); - String mimeType = getMimeType(path, responseStream); - - if (mimeType.equals("text/html")) { + if (conn.getContentType().contains("text/html")) { + InputStream responseStream = conn.getInputStream(); responseStream = jsInjector.getInjectedStream(responseStream); bridge.reset(); + return new WebResourceResponse("text/html", handler.getEncoding(), + handler.getStatusCode(), handler.getReasonPhrase(), handler.getResponseHeaders(), responseStream); } - return new WebResourceResponse(mimeType, handler.getEncoding(), - handler.getStatusCode(), handler.getReasonPhrase(), handler.getResponseHeaders(), responseStream); - } catch (SocketTimeoutException ex) { bridge.handleAppUrlLoadError(ex); } catch (Exception ex) {