public async Task <byte[]> GetByteArrayAsync(Uri url, CancellationToken cancellationToken, WebResponse webResponse = null) { if ((Uri)null != this._baseAddress && !url.IsAbsoluteUri) { url = new Uri(this._baseAddress, url); } byte[] numArray; using (IHttpConnectionResponse response = await this._webReaderManager.SendAsync(url, (IWebReader)this, cancellationToken, (string)null, (ContentType)null, true, (Uri)null, new long?(), new long?()).ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); this.Update(url, response, webResponse); using (MemoryStream memoryStream = new MemoryStream()) { await response.ContentReadStream.CopyToAsync((Stream)memoryStream, 4096, cancellationToken).ConfigureAwait(false); numArray = memoryStream.ToArray(); } } return(numArray); }
private async Task Fetch <TCached>(IRetry retry, Func <Uri, byte[], TCached> factory, WebResponse webResponse, CancellationToken cancellationToken) where TCached : class { label_12: HttpConnectionRequest request = this.CreateRequest(); using (IHttpConnectionResponse response = await this._webReader.SendAsync(request, true, cancellationToken, webResponse).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { this._firstRequestCompleted = true; Func <Uri, byte[], TCached> func1 = factory; Uri responseUri = response.ResponseUri; Func <Uri, byte[], TCached> func2 = func1; HttpConnectionWebCache connectionWebCache = this; byte[] numArray = await this.FetchObject(response, cancellationToken).ConfigureAwait(false); // ISSUE: variable of a boxed type var local = (object)func2(responseUri, numArray); connectionWebCache._cachedObject = (object)local; } else { HttpStatusCode statusCode = response.Status.StatusCode; if (HttpStatusCode.NotModified != statusCode) { if (RetryPolicy.IsRetryable(statusCode)) { if (await retry.CanRetryAfterDelayAsync(cancellationToken).ConfigureAwait(false)) { goto label_12; } } this._cachedObject = (object)null; response.EnsureSuccessStatusCode(); throw new WebException("Unable to fetch " + (object)request.Url); } } } }