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"); }); } }
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(); }); }
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(); }
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(); }
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"); } }
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(); }); }
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(); })); }
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(); })); }
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"); }); } }
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"); } }