コード例 #1
0
        public void use_anonymous_wrapping_Func_AppFunc_AppFunc_as_middleware()
        {
            Func <AppFunc, AppFunc> middleware = inner =>
            {
                return(dict =>
                {
                    var response = new OwinHttpResponse(dict);

                    response.Write("1-");
                    response.Flush();
                    return inner(dict).ContinueWith(t =>
                    {
                        response.Write("-2");
                        response.Flush();
                    });
                });
            };

            using (var server = serverFor(x => x.AddMiddleware(middleware)))
            {
                server.Scenario(_ =>
                {
                    _.Get.Action <MiddleWareInterceptedEndpoint>(x => x.get_middleware_result());
                    _.ContentShouldBe("1-I'm okay-2");
                });
            }
        }
コード例 #2
0
        public Task Invoke(IDictionary<string, object> environment)
        {
            var path = environment[OwinConstants.RequestPathKey].As<string>().TrimStart('/');

            if (path == "topics.js")
            {
                return Task.Factory.StartNew(() =>
                {
                    var response = new OwinHttpResponse(environment);
                    response.WriteContentType("text/javascript");
                    new AssetSettings().Headers.Each((key, func) => response.AppendHeader(key, func()));
                    response.Write(_topicJS);

                    response.Flush();
                });
            }

            var topic = _project.FindTopicByUrl(path);
            if (topic == null)
            {
                return _inner(environment);
            }

            return Task.Factory.StartNew(() =>
            {
                var response = new OwinHttpResponse(environment);
                response.WriteContentType("text/html");

                var html = GenerateHtml(topic);

                response.Write(html);
                response.Flush();
            });
        }
コード例 #3
0
        private void injectContent(IDictionary<string, object> environment, MemoryStream recordedStream, OwinHttpResponse response)
        {
            var html = recordedStream.ReadAllText();
            var builder = new StringBuilder(html);
            var position = html.IndexOf("</head>", 0, StringComparison.OrdinalIgnoreCase);

            if (position >= 0)
            {
                builder.Insert(position, _options.Content(environment));
            }

            response.Write(builder.ToString());
            response.Flush();
        }
コード例 #4
0
        private void injectContent(IDictionary <string, object> environment, MemoryStream recordedStream, OwinHttpResponse response)
        {
            var html     = recordedStream.ReadAllText();
            var builder  = new StringBuilder(html);
            var position = html.IndexOf("</head>", 0, StringComparison.OrdinalIgnoreCase);

            if (position >= 0)
            {
                builder.Insert(position, _options.Content(environment));
            }

            response.Write(builder.ToString());
            response.Flush();
        }
コード例 #5
0
        public void use_anonymous_wrapping_Func_AppFunc_AppFunc_as_middleware()
        {
            Func <AppFunc, AppFunc> middleware = inner => {
                return(dict => {
                    var response = new OwinHttpResponse(dict);

                    response.Write("1-");
                    response.Flush();
                    return inner(dict).ContinueWith(t => {
                        response.Write("-2");
                        response.Flush();
                    });
                });
            };

            using (var server = serverFor(x =>
            {
                x.AddMiddleware(middleware);
            }))
            {
                server.Endpoints.Get <MiddleWareInterceptedEndpoint>(x => x.get_middleware_result())
                .ReadAsText().ShouldContain("1-I'm okay-2");
            }
        }
コード例 #6
0
ファイル: FubuOwinHost.cs プロジェクト: DarthFubuMVC/fubumvc
        private void write500(IDictionary<string, object> environment, Exception exception)
        {
            using (var writer = new OwinHttpResponse(environment))
            {
                writer.WriteResponseCode(HttpStatusCode.InternalServerError);
                var document = new HtmlDocument
                {
                    Title = "Exception!"
                };

                document.Add("h1").Text("FubuMVC has detected an exception");
                document.Add("hr");
                document.Add("pre").Id("error").Text(exception.ToString());

                writer.WriteContentType(MimeType.Html.Value);
                writer.Write(document.ToString());
            }
        }
コード例 #7
0
        public Task Invoke(IDictionary<string, object> environment)
        {
            var path = environment[OwinConstants.RequestPathKey].As<string>().TrimStart('/');

            if (path == "topics.js")
            {
                return Task.Factory.StartNew(() =>
                {
                    var response = new OwinHttpResponse(environment);
                    response.WriteContentType("text/javascript");

                    response.Write(_topicJS);


                   
                    response.Flush();
                });
            }

            var topic = _project.FindTopicByUrl(path);
            if (topic == null)
            {
                return _inner(environment);
            }

            return Task.Factory.StartNew(() =>
            {
                var response = new OwinHttpResponse(environment);
                response.WriteContentType("text/html");

                response.AppendHeader(HttpGeneralHeaders.CacheControl, "no-cache, no-store, must-revalidate");
                response.AppendHeader(HttpResponseHeaders.Pragma, "no-cache");
                response.AppendHeader(HttpResponseHeaders.Expires, "0");


                var html = GenerateHtml(topic);


                response.Write(html);
                response.Flush();
            });

        }
コード例 #8
0
        public Task Invoke(IDictionary <string, object> environment)
        {
            var path = environment[OwinConstants.RequestPathKey].As <string>().TrimStart('/');

            if (path == "topics.js")
            {
                return(Task.Factory.StartNew(() =>
                {
                    var response = new OwinHttpResponse(environment);
                    response.WriteContentType("text/javascript");

                    response.Write(_topicJS);



                    response.Flush();
                }));
            }

            var topic = _project.FindTopicByUrl(path);

            if (topic == null)
            {
                return(_inner(environment));
            }

            return(Task.Factory.StartNew(() =>
            {
                var response = new OwinHttpResponse(environment);
                response.WriteContentType("text/html");

                response.AppendHeader(HttpGeneralHeaders.CacheControl, "no-cache, no-store, must-revalidate");
                response.AppendHeader(HttpResponseHeaders.Pragma, "no-cache");
                response.AppendHeader(HttpResponseHeaders.Expires, "0");


                var html = GenerateHtml(topic);


                response.Write(html);
                response.Flush();
            }));
        }
コード例 #9
0
        public Task Invoke(IDictionary <string, object> environment)
        {
            var path = environment[OwinConstants.RequestPathKey].As <string>().TrimStart('/');

            if (path == "topics.js")
            {
                return(Task.Factory.StartNew(() =>
                {
                    var response = new OwinHttpResponse(environment);
                    response.WriteContentType("text/javascript");
                    new AssetSettings().Headers.Each((key, func) => response.AppendHeader(key, func()));
                    response.Write(_topicJS);

                    response.Flush();
                }));
            }

            var topic = _project.FindTopicByUrl(path);

            if (topic == null)
            {
                return(_inner(environment));
            }

            return(Task.Factory.StartNew(() =>
            {
                var response = new OwinHttpResponse(environment);
                response.WriteContentType("text/html");

                var html = GenerateHtml(topic);


                response.Write(html);
                response.Flush();
            }));
        }
コード例 #10
0
        public void use_anonymous_wrapping_Func_AppFunc_AppFunc_as_middleware()
        {
            Func<AppFunc, AppFunc> middleware = inner =>
            {
                return dict =>
                {
                    var response = new OwinHttpResponse(dict);

                    response.Write("1-");
                    response.Flush();
                    return inner(dict).ContinueWith(t =>
                    {
                        response.Write("-2");
                        response.Flush();
                    });
                };
            };

            using (var server = serverFor(x => x.AddMiddleware(middleware)))
            {
                server.Scenario(_ =>
                {
                    _.Get.Action<MiddleWareInterceptedEndpoint>(x => x.get_middleware_result());
                    _.ContentShouldBe("1-I'm okay-2");
                });
            }
        }
コード例 #11
0
ファイル: FubuOwinHost.cs プロジェクト: jbogard/fubumvc
 private void write500(IDictionary<string, object> environment, Exception exception)
 {
     using (var writer = new OwinHttpResponse(environment))
     {
         writer.WriteResponseCode(HttpStatusCode.InternalServerError);
         writer.Write("FubuMVC has detected an exception\r\n");
         writer.Write(exception.ToString());
     }
 }
コード例 #12
0
        public void use_anonymous_wrapping_Func_AppFunc_AppFunc_as_middleware()
        {
            Func<AppFunc, AppFunc> middleware = inner => {
                return dict => {
                    var response = new OwinHttpResponse(dict);

                    response.Write("1-");
                    response.Flush();
                    return inner(dict).ContinueWith(t => {
                        response.Write("-2");
                        response.Flush();
                    });
                };
            };

            using (var server = serverFor(x =>
            {
                x.AddMiddleware(middleware);
            }))
            {
                server.Endpoints.Get<MiddleWareInterceptedEndpoint>(x => x.get_middleware_result())
                    .ReadAsText().ShouldContain("1-I'm okay-2");
            }
        }