Skip to content

Commit

Permalink
Merge pull request #25 from GEDYSIntraWare/iOS16URLEncoding
Browse files Browse the repository at this point in the history
Added decoding and encoding of the url to make it work in any iOS Ver…
  • Loading branch information
btietze committed Nov 11, 2022
2 parents a5e4339 + 9eaa1af commit ef0466b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ios/WebviewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ - (void) pluginInitialize {
- (BOOL) overrideSchemeTask: (id <WKURLSchemeTask>)urlSchemeTask {
NSURL * url = urlSchemeTask.request.URL;
NSDictionary * header = urlSchemeTask.request.allHTTPHeaderFields;
// In Versions below iOS 16 the appendString method seems to encode the string in a way that works for the request URL
NSMutableString * stringToLoad = [NSMutableString string];
[stringToLoad appendString:url.path];
NSString * method = urlSchemeTask.request.HTTPMethod;
Expand All @@ -47,8 +48,13 @@ - (BOOL) overrideSchemeTask: (id <WKURLSchemeTask>)urlSchemeTask {
if(url.query) {
[stringToLoad appendString:@"?"];
[stringToLoad appendString:url.query];
} startPath = [stringToLoad stringByReplacingOccurrencesOfString:@"/_http_proxy_" withString:@"http://"];
}
startPath = [stringToLoad stringByReplacingOccurrencesOfString:@"/_http_proxy_" withString:@"http://"];
startPath = [startPath stringByReplacingOccurrencesOfString:@"/_https_proxy_" withString:@"https://"];
// Since iOS 16 the url is not automatically encoded anymore.
// Here it is decoded and encoded again, so it is always encoded as needed regardless of the iOS Version.
startPath = [startPath stringByRemovingPercentEncoding];
startPath = [startPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL * requestUrl = [NSURL URLWithString:startPath];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:method];
Expand Down

0 comments on commit ef0466b

Please sign in to comment.