private OfflineEntry GetCacheEntry(Uri uri, Guid requestId) { var filteredQueryParameters = uri.ParseQueryString() .Where(p => p.Key != "_") // Sanitize empty values (query string wo value) .Select(p => p.Key + (p.Value != null ? "=" : string.Empty) + (string.IsNullOrEmpty(p.Value) ? string.Empty : p.Value)); var mappedUri = new UriBuilder(uri); mappedUri.Query = string.Join("&", filteredQueryParameters); // TODO: review if trimming trailing slash is correct var flatString = mappedUri.Uri.ToString().TrimEnd('/'); OfflineEntry entry = null; lock (cacheIndex) { if (!cacheIndex.TryGetValue(flatString, out entry)) { entry = new OfflineEntry { RequestId = requestId, Key = flatString }; } } return entry; }
private static async Task<HttpResponseMessage> RetrieveOfflineResponseMessageAsync(HttpRequestMessage request, OfflineEntry entry, StorageFile file) { var cachedByteArray = await ReadBytesAsync(file); var response = new HttpResponseMessage(HttpStatusCode.OK); response.RequestMessage = request; response.Content = new ByteArrayContent(cachedByteArray); MediaTypeHeaderValue contentType; if (MediaTypeHeaderValue.TryParse(entry.ContentType, out contentType)) { response.Content.Headers.ContentType = contentType; } return response; }