public InterceptMode InterceptOnce() { string etag = _response.ETag; if (string.IsNullOrEmpty(etag)) { return(InterceptMode.DoingNothing); } if (etag.StartsWith("\"", StringComparison.Ordinal) && etag.EndsWith("\"", StringComparison.Ordinal)) { _compressedETag = etag.Substring(0, etag.Length - 1) + "^" + _encoding.Name + "\""; } else { _compressedETag = "\"" + etag + "^" + _encoding.Name + "\""; } HttpStatusCode statusCode = (HttpStatusCode)_response.StatusCode; if (statusCode == HttpStatusCode.NotModified) { return(InterceptMode.SentFromStorage); } var key = new CompressedKey { ETag = _compressedETag, RequestPath = _request.Path.Value, RequestQueryString = _request.QueryString.Value, RequestMethod = _request.Method, }; _compressedItem = _storage.Open(key); if (_compressedItem != null) { return(InterceptMode.SentFromStorage); } _compressedItemBuilder = _storage.Create(key); _compressingStream = _encoding.CompressTo(_compressedItemBuilder.Stream); return(InterceptMode.CompressingToStorage); }
public InterceptMode InterceptOnce() { StringSegment etag = SingleSegment(_response, "ETag"); if (!etag.HasValue) { return InterceptMode.DoingNothing; } if (etag.StartsWith("\"", StringComparison.Ordinal) && etag.EndsWith("\"", StringComparison.Ordinal)) { _compressedETag = etag.Substring(0, etag.Count - 1) + "^" + _encoding.Name + "\""; } else { _compressedETag = "\"" + etag.Value + "^" + _encoding.Name + "\""; } HttpStatusCode statusCode = (HttpStatusCode)_response.StatusCode; if (statusCode == HttpStatusCode.NotModified) { return InterceptMode.SentFromStorage; } var key = new CompressedKey { ETag = _compressedETag, RequestPath = _request.Path, RequestQueryString = _request.QueryString, RequestMethod = _request.Method, }; _compressedItem = _storage.Open(key); if (_compressedItem != null) { return InterceptMode.SentFromStorage; } _compressedItemBuilder = _storage.Create(key); _compressingStream = _encoding.CompressTo(_compressedItemBuilder.Stream); return InterceptMode.CompressingToStorage; }
public ItemBuilder(CompressedKey key, string physicalPath) { Key = key; PhysicalPath = physicalPath; Stream = new FileStream(PhysicalPath, FileMode.Create, FileAccess.Write, FileShare.None); }
private void AddHandleInDictionary(CompressedKey key, ItemHandle handle) { lock (_itemsLock) { ItemHandle addingHandle = handle.Clone(); ItemHandle existingHandle; if (_items.TryGetValue(key, out existingHandle)) { existingHandle.Dispose(); } _items[key] = addingHandle; } }
public ICompressedItemBuilder Create(CompressedKey key) { // TODO: break down into buckets to avoid files-per-folder limits string physicalPath = Path.Combine(_storagePath, Guid.NewGuid().ToString("n")); return new ItemBuilder(key, physicalPath); }
public ICompressedItemHandle Open(CompressedKey key) { lock (_itemsLock) { ItemHandle handle; if (_items.TryGetValue(key, out handle)) { return handle.Clone(); } return null; } }