|
34 | 34 | import java.util.Map; |
35 | 35 | import java.util.UUID; |
36 | 36 |
|
| 37 | +import java.net.URL; |
| 38 | +import java.net.URLConnection; |
| 39 | + |
| 40 | + |
37 | 41 | /** |
38 | 42 | * Helper class meant to be used with the android.webkit.WebView class to enable hosting assets, |
39 | 43 | * resources and other data on 'virtual' http(s):// URL. |
@@ -217,14 +221,22 @@ private static WebResourceResponse createWebResourceResponse(String mimeType, St |
217 | 221 | */ |
218 | 222 | public WebResourceResponse shouldInterceptRequest(Uri uri, WebResourceRequest request) { |
219 | 223 | if (isProxySource(uri)) { |
220 | | - String fixedUri = uri.toString().replaceFirst("http://localhost/_app_proxy_/", ""); |
221 | | - |
222 | | - InputStream responseStream = new LollipopLazyInputStream(handler, Uri.parse(fixedUri)); |
223 | | - String mimeType = getMimeType(path, responseStream); |
224 | | - return createWebResourceResponse(mimeType, handler.getEncoding(), |
225 | | - handler.getStatusCode(), handler.getReasonPhrase(), handler.getResponseHeaders(), responseStream); |
| 224 | + try { |
| 225 | + String fixedUri = uri.toString().replaceFirst("http://localhost/_app_proxy_/", ""); |
| 226 | + URL httpsUrl = new URL(fixedUri); |
| 227 | + URLConnection connection = httpsUrl.openConnection(); |
| 228 | + connection.setRequestProperty("Access-Control-Allow-Origin", "*"); |
| 229 | + connection.setRequestProperty("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS"); |
| 230 | + connection.setRequestProperty("Access-Control-Allow-Headers", "agent, user-data, Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); |
| 231 | + |
| 232 | + return new WebResourceResponse(connection.getContentType(), connection.getContentEncoding(), connection.getInputStream()); |
| 233 | + } catch (Exception e) { |
| 234 | + //an error occurred |
| 235 | + return null; |
| 236 | + } |
226 | 237 | } |
227 | 238 |
|
| 239 | + |
228 | 240 | PathHandler handler; |
229 | 241 | synchronized (uriMatcher) { |
230 | 242 | handler = (PathHandler) uriMatcher.match(uri); |
|
0 commit comments