// NSURLConnection delegates (generally we pass these on to our client)

        public override NSUrlRequest WillSendRequest(NSUrlConnection connection, NSUrlRequest request, NSUrlResponse response)
        {
            // Thanks to Nick Dowell https://gist.github.com/1885821
            if (response != null)
            {
                var redirectableRequest = Request.MutableCopy as NSMutableUrlRequest;

                // We need to remove our header so we know to handle this request and cache it.
                // There are 3 requests in flight: the outside request, which we handled, the internal request,
                // which we marked with our header, and the redirectableRequest, which we're modifying here.
                // The redirectable request will cause a new outside request from the NSURLProtocolClient, which
                // must not be marked with our header.
                redirectableRequest.SetValueForKey(null, MtRnCachingUrlHeader);

                var cachePath = CachePathForRequest(this.Request);
                var cache     = new MtRnCachedData();
                cache.Response        = response;
                cache.Data            = this.Data;
                cache.RedirectRequest = redirectableRequest;
                NSKeyedArchiver.ArchiveRootObjectToFile(cache, cachePath);
                this.Client.Redirected(this, redirectableRequest, response);
                return(redirectableRequest);
            }
            else
            {
                return(request);
            }
        }
        public override void FinishedLoading(NSUrlConnection connection)
        {
            Client.FinishedLoading(this);

            var cachePath = CachePathForRequest(this.Request);
            var cache     = new MtRnCachedData();

            cache.Response = this.Response;
            cache.Data     = this.Data;
            NSKeyedArchiver.ArchiveRootObjectToFile(cache, cachePath);

            Connection = null;
            Data       = null;
            Response   = null;
        }