Example #1
0
        public DoNext Filter(ServiceArguments arguments)
        {
            string etag = null;

            arguments.Get <IRequestData>().ValuesFor(RequestDataSource.Header)
            .Value(HttpRequestHeaders.IfNoneMatch, value => etag = value.RawValue as string);

            if (etag == null)
            {
                return(DoNext.Continue);
            }

            var resourceHash = _hashing(arguments);
            var headers      = _cache.Current(resourceHash);
            var currentEtag  = headers.ValueFor(HttpResponseHeader.ETag);

            if (etag != currentEtag)
            {
                return(DoNext.Continue);
            }


            var writer = arguments.Get <IHttpWriter>();

            writer.WriteResponseCode(HttpStatusCode.NotModified);

            headers.Each(x => x.Replay(writer));

            return(DoNext.Stop);
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            if (arguments.Has(typeof(Latch)))
            {
                return(DoNext.Stop);
            }


            var request = arguments.Get <IHttpRequest>();

            if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding))
            {
                return(DoNext.Continue);
            }

            var acceptEncoding = request
                                 .GetSingleHeader(HttpRequestHeaders.AcceptEncoding);


            var encoding = _encoders.MatchFor(acceptEncoding);
            var writer   = arguments.Get <IHttpResponse>();

            writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);

            writer.UseEncoding(encoding);

            arguments.Set(typeof(Latch), new Latch());

            return(DoNext.Continue);
        }
        public void should_return_stop_and_write_304_response_code_if_the_ifnonematch_header_matches_the_current_etag()
        {
            setRequestIfNoneMatch("12345");

            theCache.Register(theHash, new Header[] { new Header(HttpResponseHeader.ETag, "12345"), });

            theFilter.Filter(theServiceArguments).ShouldEqual(DoNext.Stop);

            theServiceArguments.Get <IHttpWriter>()
            .AssertWasCalled(x => x.WriteResponseCode(HttpStatusCode.NotModified));
        }
Example #4
0
        private void setRequestIfNoneMatch(string etag)
        {
            var request = theServiceArguments.Get <ICurrentHttpRequest>();

            request
            .Stub(x => x.HasHeader(HttpRequestHeader.IfNoneMatch))
            .Return(true);


            request.Stub(x => x.GetHeader(HttpRequestHeader.IfNoneMatch)).Return(new string[] { etag });


            theHeaders[HttpRequestHeaders.IfNoneMatch] = etag;
        }
        public void should_return_stop_and_write_304_response_code_if_the_ifnonematch_header_matches_the_current_etag()
        {
            var theResourceHash = Guid.NewGuid().ToString();

            theServiceArguments.Get <ICurrentChain>().Stub(x => x.ResourceHash())
            .Return(theResourceHash);

            setRequestIfNoneMatch("12345");

            theCache.Register(theResourceHash, "12345");

            theFilter.Filter(theServiceArguments).ShouldEqual(DoNext.Stop);

            theServiceArguments.Get <IHttpWriter>()
            .AssertWasCalled(x => x.WriteResponseCode(HttpStatusCode.NotModified));
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            string etag = null;

            arguments.Get<AggregateDictionary>().Value(RequestDataSource.Header.ToString(), HttpRequestHeaders.IfNoneMatch, (key, value) => etag = (string) value);

            if (etag == null) return DoNext.Continue;

            var resourceHash = arguments.Get<ICurrentChain>().ResourceHash();
            var currentEtag = _cache.Current(resourceHash);

            if (etag != currentEtag) return DoNext.Continue;

            arguments.Get<IHttpWriter>().WriteResponseCode(HttpStatusCode.NotModified);
            return DoNext.Stop;
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            arguments
                .Get<IRequestData>()
                .ValuesFor(RequestDataSource.Header)
                .Value(HttpRequestHeaders.AcceptEncoding, x =>
                {
                    var encoding = _encoders.MatchFor(x.RawValue as string);
                    var writer = arguments.Get<IHttpWriter>();

                    writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);
                    writer.UseEncoding(encoding);
                });

            return DoNext.Continue;
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            arguments
            .Get <IRequestData>()
            .ValuesFor(RequestDataSource.Header)
            .Value(HttpRequestHeaders.AcceptEncoding, x =>
            {
                var encoding = _encoders.MatchFor(x.RawValue as string);
                var writer   = arguments.Get <IHttpWriter>();

                writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);
                writer.UseEncoding(encoding);
            });

            return(DoNext.Continue);
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            string etag = null;

            arguments.Get<IRequestData>().ValuesFor(RequestDataSource.Header)
                .Value(HttpRequestHeaders.IfNoneMatch, value => etag = value.RawValue as string);

            if (etag == null) return DoNext.Continue;

            var resourceHash = arguments.Get<ICurrentChain>().ResourceHash();
            var currentEtag = _cache.Current(resourceHash);

            if (etag != currentEtag) return DoNext.Continue;

            arguments.Get<IHttpWriter>().WriteResponseCode(HttpStatusCode.NotModified);
            return DoNext.Stop;
        }
Example #10
0
        public void Invoke(ServiceArguments arguments, IDictionary <string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);

            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().RootChain = _chain;
            }

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            IActionBehavior behavior = null;

            if (arguments.Has(typeof(IChainExecutionLog)))
            {
                arguments.Get <IChainExecutionLog>().Trace("Building the Behaviors", () =>
                {
                    behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
                });
            }
            else
            {
                behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            }


            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });

            behavior.Invoke();
        }
Example #11
0
        public void Invoke(ServiceArguments arguments, IDictionary<string, object> routeValues, IRequestCompletion requestCompletion)
        {
            var currentChain = new CurrentChain(_chain, routeValues);
            arguments.Set(typeof(ICurrentChain), currentChain);
            arguments.Set(typeof(IRequestCompletion), requestCompletion);

            if (arguments.Has(typeof (IChainExecutionLog)))
            {
                arguments.Get<IChainExecutionLog>().RootChain = _chain;
            }

            if (_chain.Filters.Any(filter => filter.Filter(arguments) == DoNext.Stop))
            {
                return;
            }

            IActionBehavior behavior = null;

            if (arguments.Has(typeof (IChainExecutionLog)))
            {
                arguments.Get<IChainExecutionLog>().Trace("Building the Behaviors", () =>
                {
                    behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
                });
            }
            else
            {
                behavior = _factory.BuildBehavior(arguments, _chain.UniqueId);
            }

            
            requestCompletion.WhenCompleteDo(x =>
            {
                var disposable = behavior as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            });

            behavior.Invoke();
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            if (arguments.Has(typeof(Latch))) return DoNext.Stop;

            arguments
                .Get<IRequestData>()
                .ValuesFor(RequestDataSource.Header)
                .Value(HttpRequestHeaders.AcceptEncoding, x =>
                {
                    var encoding = _encoders.MatchFor(x.RawValue as string);
                    var writer = arguments.Get<IHttpResponse>();

                    writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);
                    writer.UseEncoding(encoding);
                });

            arguments.Set(typeof(Latch), new Latch());

            return DoNext.Continue;
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            if (arguments.Has(typeof (Latch))) return DoNext.Stop;


            var request = arguments.Get<IHttpRequest>();
            if (!request.HasHeader(HttpRequestHeaders.AcceptEncoding)) return DoNext.Continue;

            var acceptEncoding = request
                .GetSingleHeader(HttpRequestHeaders.AcceptEncoding);


            var encoding = _encoders.MatchFor(acceptEncoding);
            var writer = arguments.Get<IHttpResponse>();
            writer.AppendHeader(HttpRequestHeaders.ContentEncoding, encoding.MatchingEncoding.Value);

            writer.UseEncoding(encoding);

            arguments.Set(typeof (Latch), new Latch());

            return DoNext.Continue;
        }
Example #14
0
        public DoNext Filter(ServiceArguments arguments)
        {
            string etag = null;

            var request = arguments.Get <IHttpRequest>();

            if (!request.HasHeader(HttpRequestHeader.IfNoneMatch))
            {
                return(DoNext.Continue);
            }

            etag = request.GetHeader(HttpRequestHeader.IfNoneMatch).FirstOrDefault();

            if (etag.IsEmpty())
            {
                return(DoNext.Continue);
            }



            var resourceHash = _hashing(arguments);
            var headers      = _cache.Current(resourceHash);
            var currentEtag  = headers.ValueFor(HttpResponseHeader.ETag);

            if (etag != currentEtag)
            {
                return(DoNext.Continue);
            }

            var writer = arguments.Get <IHttpResponse>();

            writer.WriteResponseCode(HttpStatusCode.NotModified);


            headers.Each(x => x.Replay(writer));


            return(DoNext.Stop);
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            string etag = null;

            arguments.Get<IRequestData>().ValuesFor(RequestDataSource.Header)
                .Value(HttpRequestHeaders.IfNoneMatch, value => etag = value.RawValue as string);

            if (etag == null) return DoNext.Continue;

            var resourceHash = _hashing(arguments);
            var headers = _cache.Current(resourceHash);
            var currentEtag = headers.ValueFor(HttpResponseHeader.ETag);

            if (etag != currentEtag) return DoNext.Continue;

            var writer = arguments.Get<IHttpWriter>();
            writer.WriteResponseCode(HttpStatusCode.NotModified);

            headers.Each(x => x.Replay(writer));

            return DoNext.Stop;
        }
        public DoNext Filter(ServiceArguments arguments)
        {
            string etag = null;

            arguments.Get <AggregateDictionary>().Value(RequestDataSource.Header.ToString(), HttpRequestHeaders.IfNoneMatch, (key, value) => etag = (string)value);

            if (etag == null)
            {
                return(DoNext.Continue);
            }

            var resourceHash = arguments.Get <ICurrentChain>().ResourceHash();
            var currentEtag  = _cache.Current(resourceHash);

            if (etag != currentEtag)
            {
                return(DoNext.Continue);
            }


            arguments.Get <IHttpWriter>().WriteResponseCode(HttpStatusCode.NotModified);
            return(DoNext.Stop);
        }
Example #17
0
        public DoNext Filter(ServiceArguments arguments)
        {
            string etag = null;

            var request = arguments.Get<ICurrentHttpRequest>();
            if (!request.HasHeader(HttpRequestHeader.IfNoneMatch)) return DoNext.Continue;

            etag = request.GetHeader(HttpRequestHeader.IfNoneMatch).FirstOrDefault();

            if (etag.IsEmpty()) return DoNext.Continue;

            var resourceHash = _hashing(arguments);
            var headers = _cache.Current(resourceHash);
            var currentEtag = headers.ValueFor(HttpResponseHeader.ETag);

            if (etag != currentEtag) return DoNext.Continue;

            var writer = arguments.Get<IHttpWriter>();
            writer.WriteResponseCode(HttpStatusCode.NotModified);

            headers.Each(x => x.Replay(writer));

            return DoNext.Stop;
        }
        public IActionBehavior BuildBehavior(ServiceArguments arguments, Guid behaviorId)
        {
            var diagnostics = _container.Get<DiagnosticBehavior>();

            var writer = arguments.Has(typeof(IOutputWriter))
                ? arguments.Get<IOutputWriter>()
                : _container.Get<IOutputWriter>();

            var report = _container.Get<IDebugReport>();
            arguments.Set(typeof(IOutputWriter), new RecordingOutputWriter(report, writer));

            var behavior = _inner.BuildBehavior(arguments, behaviorId);
            diagnostics.Inner = behavior;

            return diagnostics;
        }
Example #19
0
 public void invoke_happy_path_will_put_the_current_chain_together()
 {
     theInvoker.Invoke(theArguments, theRouteData, new RequestCompletion());
     theArguments.Get <ICurrentChain>().ShouldBeOfType <CurrentChain>()
     .ResourceHash().ShouldEqual(new CurrentChain(theChain, theRouteData).ResourceHash());
 }