This is canInitWithRequest
in NSURLProtocol
:
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
// only handle http requests we haven't marked with our header.
if ([[[request URL] scheme] isEqualToString:@"http"] &&
([request valueForHTTPHeaderField:RNCachingURLHeader] == nil)) {
return YES;
}
return NO;
}
But I want NSURLProtocol
to allow https requests as well.
I tried this but all requests fail when called :
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
// only handle http requests we haven't marked with our header.
if (([[[request URL] scheme] isEqualToString:@"http"] || [[[request URL] scheme] isEqualToString:@"https"]) &&
([request valueForHTTPHeaderField:RNCachingURLHeader] == nil)) {
return YES;
}
return NO;
}
One example is of a login request which has https scheme. In the above function, YES is returned but when the login request is called, I get this error in log :
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
However if I remove check of https in canInitWithRequest
, I get no error.
I am using RNCachingURLProtocol to cache the requests.
How may I achieve this.