public virtual async Task <ContentType> DetectContentTypeAsync(Uri url, ContentKind contentKind, CancellationToken cancellationToken, IWebReader parent = null) { ContentType contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>) this._contentTypeDetector.GetContentType(url, (string)null, (string)null)); ContentType contentType1; if ((ContentType)null != contentType) { Debug.WriteLine("HttpClientWebReaderManager.DetectContentTypeAsync() url ext \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; } else { Uri referrer = HttpClientWebReaderManager.GetReferrer(parent); using (HttpClient client = this._httpClientFactory.CreateClient(url, referrer, ContentKind.Unknown, (ContentType)null)) { try { using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, url)) { using (HttpResponseMessage httpResponseMessage = await HttpClientExtensions.SendAsync(client, request, HttpCompletionOption.ResponseHeadersRead, cancellationToken, referrer, new long?(), new long?()).ConfigureAwait(false)) { if (httpResponseMessage.IsSuccessStatusCode) { contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>)HttpClientContentTypeDetectorExtensions.GetContentType(this._contentTypeDetector, request.RequestUri, httpResponseMessage.Content.Headers, HttpContentExtensions.FileName(httpResponseMessage.Content))); if ((ContentType)null != contentType) { Debug.WriteLine("HttpClientWebReaderManager.DetectContentTypeAsync() url HEAD \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; goto label_49; } } } } } catch (HttpRequestException ex) { } try { using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url)) { using (HttpResponseMessage httpResponseMessage = await HttpClientExtensions.SendAsync(client, request, HttpCompletionOption.ResponseHeadersRead, cancellationToken, referrer, new long?(0L), new long?(0L)).ConfigureAwait(false)) { if (httpResponseMessage.IsSuccessStatusCode) { contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>)HttpClientContentTypeDetectorExtensions.GetContentType(this._contentTypeDetector, request.RequestUri, httpResponseMessage.Content.Headers, HttpContentExtensions.FileName(httpResponseMessage.Content))); if ((ContentType)null != contentType) { Debug.WriteLine("HttpClientWebReaderManager.DetectContentTypeAsync() url range GET \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; goto label_49; } } } } } catch (HttpRequestException ex) { } try { using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url)) { using (HttpResponseMessage httpResponseMessage = await HttpClientExtensions.SendAsync(client, request, HttpCompletionOption.ResponseHeadersRead, cancellationToken, referrer, new long?(), new long?()).ConfigureAwait(false)) { if (httpResponseMessage.IsSuccessStatusCode) { contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>)HttpClientContentTypeDetectorExtensions.GetContentType(this._contentTypeDetector, request.RequestUri, httpResponseMessage.Content.Headers, HttpContentExtensions.FileName(httpResponseMessage.Content))); if ((ContentType)null != contentType) { Debug.WriteLine("HttpClientWebReaderManager.DetectContentTypeAsync() url GET \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; goto label_49; } } } } } catch (HttpRequestException ex) { } } Debug.WriteLine("HttpClientWebReaderManager.DetectContentTypeAsync() url header \"{0}\" unknown type", (object)url); contentType1 = (ContentType)null; } label_49: return(contentType1); }