Skip to content

Commit 3754bb6

Browse files
committed
Create web proxy
1 parent 0eb8a37 commit 3754bb6

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/ios/IONAssetHandler.m

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,31 @@ - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)ur
2323
NSURL * url = urlSchemeTask.request.URL;
2424
NSString * stringToLoad = url.path;
2525
NSString * scheme = url.scheme;
26+
NSString * method = urlSchemeTask.request.HTTPMethod;
27+
NSData * data;
28+
NSInteger statusCode;
2629

2730
if ([scheme isEqualToString:self.scheme]) {
2831
if ([stringToLoad hasPrefix:@"/_app_file_"]) {
2932
startPath = [stringToLoad stringByReplacingOccurrencesOfString:@"/_app_file_" withString:@""];
33+
} else if ([stringToLoad hasPrefix:@"/_http_proxy_"]||[stringToLoad hasPrefix:@"/_https_proxy_"]) {
34+
startPath = [stringToLoad stringByReplacingOccurrencesOfString:@"/_http_proxy_" withString:@"http://"];
35+
startPath = [stringToLoad stringByReplacingOccurrencesOfString:@"/_https_proxy_" withString:@"https://"];
36+
NSLog(@"Proxy %@", startPath);
37+
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
38+
[request setHTTPMethod:method];
39+
[request setURL:[NSURL URLWithString:startPath]];
40+
[request setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:[NSHTTPCookieStorage sharedHTTPCookieStorage].cookies]];
41+
[request HTTPShouldHandleCookies];
42+
43+
NSError *error = nil;
44+
NSHTTPURLResponse *responseCode = nil;
45+
46+
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
47+
statusCode = [responseCode statusCode];
48+
if (!error) {
49+
NSLog(@"%@", error);
50+
}
3051
} else {
3152
startPath = self.basePath;
3253
if ([stringToLoad isEqualToString:@""] || [url.pathExtension isEqualToString:@""]) {
@@ -37,8 +58,10 @@ - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)ur
3758
}
3859
}
3960

40-
NSData * data = [[NSData alloc] initWithContentsOfFile:startPath];
41-
NSInteger statusCode = 200;
61+
if(!data) {
62+
data = [[NSData alloc] initWithContentsOfFile:startPath];
63+
}
64+
statusCode = 200;
4265
if (!data) {
4366
statusCode = 404;
4467
}

src/www/util.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ var WebView = {
1111
if (url.startsWith('file://')) {
1212
return window.WEBVIEW_SERVER_URL + url.replace('file://', '/_app_file_');
1313
}
14+
if (url.startsWith('http://')) {
15+
return window.WEBVIEW_SERVER_URL + url.replace('http://', '/_http_proxy_');
16+
}
17+
if (url.startsWith('https://')) {
18+
return window.WEBVIEW_SERVER_URL + url.replace('https://', '/_https_proxy_');
19+
}
1420
if (url.startsWith('content://')) {
1521
return window.WEBVIEW_SERVER_URL + url.replace('content:/', '/_app_content_');
1622
}

0 commit comments

Comments
 (0)