示例#1
0
        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;
            }
        }
示例#2
0
 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);
 }
示例#4
0
        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);
        }
示例#5
0
        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));
        }