public async Task Invoke(IDictionary <string, object> environment) { IEncoding compression = SelectCompression(environment); if (compression == null) { await _next(environment); return; } ICompressedStorage storage = GetStorage(environment); if (storage == null) { await _next(environment); return; } var context = new StaticCompressionContext(environment, _options, compression, storage); context.Attach(); try { await _next(environment); await context.Complete(); } catch (Exception) { context.Detach(); throw; } }
public StaticCompressionContext(IDictionary <string, object> environment, StaticCompressionOptions options, IEncoding encoding, ICompressedStorage storage) { _environment = environment; _options = options; _encoding = encoding; _encodingSuffix = "^" + _encoding.Name; _encodingSuffixQuote = "^" + _encoding.Name + "\""; _storage = storage; _request = new OwinRequest(environment); _response = new OwinResponse(environment); }
public StaticCompressionContext(IDictionary<string, object> environment, StaticCompressionOptions options, IEncoding encoding, ICompressedStorage storage) { _environment = environment; _options = options; _encoding = encoding; _encodingSuffix = "^" + _encoding.Name; _encodingSuffixQuote = "^" + _encoding.Name + "\""; _storage = storage; _request = new OwinRequest(environment); _response = new OwinResponse(environment); }
private ICompressedStorage GetStorageOnce(IDictionary <string, object> environment) { ICompressedStorage storage = _options.CompressedStorageProvider.Create(); var onAppDisposing = new OwinRequest(environment).Get <CancellationToken>("host.OnAppDisposing"); if (onAppDisposing != CancellationToken.None) { onAppDisposing.Register(storage.Dispose); } return(storage); }
public Task Invoke(IDictionary <string, object> environment) { IEncoding compression = SelectCompression(environment); if (compression == null) { return(_next(environment)); } ICompressedStorage storage = GetStorage(environment); if (storage == null) { return(_next(environment)); } var context = new StaticCompressionContext(environment, _options, compression, storage); context.Attach(); return(_next(environment) .Then((Func <Task>)context.Complete) .Catch(context.Complete)); }