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