本文整理汇总了C#中Response.Finish方法的典型用法代码示例。如果您正苦于以下问题:C# Response.Finish方法的具体用法?C# Response.Finish怎么用?C# Response.Finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response.Finish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Call
public static AppAction Call(AppAction app)
{
return (env, fault, result) => {
Action<Exception, Action<ArraySegment<byte>>> writeErrorPageBody = (ex, write) => {
write("<h1>Server Error</h1>".ToBytes());
write("<p>".ToBytes());
write(ex.Message.ToBytes()); //TODO: htmlencode, etc
write("</p>".ToBytes());
};
Action<Exception> sendErrorPageResponse = ex => {
var response = new Response(result) {Status = 500, ContentType = "text/html"};
writeErrorPageBody(ex, value => response.Write(value));
response.Finish();
};
try {
// intercept app-fault with sendErrorPageResponse, which is the full error page response
// intercept body-error with writeErrorPageBody, which adds the error text to the output and completes the response
app(env, sendErrorPageResponse, (status, headers, body) =>
result(status, headers, body.Filter((subscribe, next, error, complete) =>
subscribe(next, ex => {
writeErrorPageBody(ex, data => next.InvokeSync(data));
complete();
}, complete))));
}
catch (Exception ex) {
sendErrorPageResponse(ex);
}
};
}
示例2: Create
public static AppAction Create()
{
return (env, fault, result) => {
var request = new Request(env);
var response = new Response(result) {
Status = 200,
ContentType = "text/html"
};
response.Write("<h1>Sample1</h1>");
response.Write("<p>Hello world</p>");
response.Write("<p>This part is being added to the response helper's buffer. The result callback has not been invoked yet.</p>");
response.Finish(() => {
response.Write("<p>The result callback has been invoked. This part is going out live, but you can no longer change http response status or headers.</p>");
response.Write("<p>request.PathInfo=").Write(request.PathInfo).Write("</p>");
response.Write("<p>request.ScriptName=").Write(request.ScriptName).Write("</p>");
response.Write("<p> see also <a href='wilson'>Wilson</a> and <a href='wilsonasync'>WilsonAsync</a></p>");
response.Write(new byte[] {65, 66, 67, 68});
response.Write("<p>And now for something completely different.");
throw new ApplicationException("Something completely different");
});
};
}
示例3: Call
public dynamic[] Call(IDictionary<string, dynamic> environment)
{
var request = new Request(environment);
string lobster;
string href;
if (request.GET.ContainsKey("flip") && request.GET["flip"] == "left")
{
lobster = string.Join("\n", LobsterString.Split('\n').Select(line => new string(line.PadRight(42).Reverse().ToArray())));
href = "?flip=right";
}
else if (request.GET.ContainsKey("flip") && request.GET["flip"] == "crash")
{
throw new InvalidOperationException("Lobster crashed!");
}
else
{
lobster = LobsterString;
href = "?flip=left";
}
var response = new Response();
response.Write("<title>Lobstericious!</title>");
response.Write("<pre>");
response.Write(lobster);
response.Write("</pre>");
response.Write("<p><a href='" + href + "'>flip!</a></p>");
response.Write("<p><a href='?flip=crash'>crash!</a></p>");
return response.Finish();
}
示例4: App
public static FnApp App()
{
return (env, fault, result) => {
var request = new Request(env);
var response = new Response(result);
var wilson = "left - right\r\n123456789012\r\nhello world!\r\n";
var href = "?flip=left";
if (request.GET["flip"] == "left") {
wilson = wilson.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
.Select(line => new string(line.Reverse().ToArray()))
.Aggregate("", (agg, line) => agg + line + Environment.NewLine);
href = "?flip=right";
}
response.Write("<title>Hutchtastic</title>");
response.Write("<pre>");
response.Write(wilson);
response.Write("</pre>");
if (request.GET["flip"] == "crash") {
throw new ApplicationException("Wilson crashed!");
}
response.Write("<p><a href='" + href + "'>flip!</a></p>");
response.Write("<p><a href='?flip=crash'>crash!</a></p>");
response.Finish();
};
}
示例5: Something
public async Task Something(Request req, Response res, string echo)
{
await res.Start();
await res.Write("SomeOtherController.Something");
await res.Write("\n" + echo);
await res.Finish();
}
示例6: Index
public async Task Index(Request req, Response res)
{
await res.Start();
await res.Write("SomeController.Index");
throw new Exception("bad news everyone");
await res.Finish();
}
示例7: Should_Have_Sensible_Default_Values
public void Should_Have_Sensible_Default_Values()
{
var response = new Response();
var res = response.Finish();
var status = res[0];
var header = res[1];
var body = (IIterable)res[2];
Assert.AreEqual(200, status);
CollectionAssert.AreEquivalent(new Hash { { "Content-Type", "text/html" } }, header);
body.Each(part => Assert.AreEqual(string.Empty, part));
}
示例8: Finish_will_call_result_delegate_with_current_status_and_headers
public void Finish_will_call_result_delegate_with_current_status_and_headers()
{
var response = new Response(Result)
{
Status = "200 Blah",
ContentType = "text/blah",
};
Assert.That(_status, Is.Null);
response.Finish();
Assert.That(_status, Is.EqualTo("200 Blah"));
Assert.That(_headers["Content-Type"], Is.EqualTo("text/blah"));
}
示例9: ShowEnvironment
public static AppDelegate ShowEnvironment()
{
return (env, result, fault) =>
{
var response = new Response(result) {Status = "200 OK", ContentType = "text/xml"};
response.Finish((error, complete) =>
{
var detail = env.Select(kv => new XElement(kv.Key, kv.Value));
var xml = new XElement("xml", detail.OfType<object>().ToArray());
response.Write(xml.ToString());
complete();
});
};
}
示例10: Should_Not_Add_Or_Change_Content_Length_When_Finishing
public void Should_Not_Add_Or_Change_Content_Length_When_Finishing()
{
var response = new Response();
response.Status = 200;
response.Finish();
Assert.IsFalse(response.Headers.ContainsKey("Content-Length"));
response = new Response();
response.Status = 200;
response.Headers["Content-Length"] = "10";
response.Finish();
Assert.AreEqual("10", response.Headers["Content-Length"]);
}
示例11: Can_Be_Written_To
public void Can_Be_Written_To()
{
var response = new Response();
var body = response.Finish(_ =>
{
response.Write("foo");
response.Write("bar");
response.Write("baz");
})[2];
var parts = new List<string>();
((IIterable)body).Each(part => parts.Add(part));
CollectionAssert.AreEquivalent(new List<string> { "foo", "bar", "baz" }, parts);
}
示例12: Create
public static AppAction Create()
{
return (env, fault, result) => {
var request = new Request(env);
if (request.RequestMethod == "GET") {
new Response(result) {Status = 200, ContentType = "text/html"}
.Write(@"
<form method='post'>
<input type='text' name='hello'/>
<input type='submit' name='ok' value='ok'/>
</form>")
.Finish();
}
else if (request.RequestMethod == "POST") {
// stream request body
var body = new MemoryStream();
request.Body.Subscribe(
data => body.Write(data.Result.Array, data.Result.Offset, data.Result.Count),
fault,
() => {
// completion continues
var response = new Response(result) {
Status = 200,
ContentType = "text/html"
};
response.Finish(() => {
response.Write("<p>You posted ");
response.Write(body.Length);
response.Write(" bytes of form data<p>");
var form = ParamDictionary.Parse(Encoding.Default.GetString(body.ToArray()));
response.Write("<ul>");
foreach (var kv in form) {
response.Write("<li>").Write(kv.Key).Write(": ").Write(kv.Value).Write("</li>");
}
response.Write("</ul>");
});
});
}
else {
new Response(result) {Status = 404}.Finish();
}
};
}
示例13: executeRoute
private static void executeRoute(RouteData routeData, Response response, OwinRequestBody request)
{
var arguments = new OwinServiceArguments(routeData, request, response);
var invoker = routeData.RouteHandler.As<FubuRouteHandler>().Invoker;
try
{
invoker.Invoke(arguments, routeData.Values);
}
catch (Exception ex)
{
write500(response, ex);
}
finally
{
response.Finish();
}
}
示例14: AppAsync
public static FnApp AppAsync()
{
return (env, fault, result) => {
var request = new Request(env);
var response = new Response(result);
var wilson = "left - right\r\n123456789012\r\nhello world!\r\n";
ThreadPool.QueueUserWorkItem(_ => {
try {
var href = "?flip=left";
if (request.GET["flip"] == "left") {
wilson = wilson.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
.Select(line => new string(line.Reverse().ToArray()))
.Aggregate("", (agg, line) => agg + line + Environment.NewLine);
href = "?flip=right";
}
response.Finish((fault2, complete) => TimerLoop(350, fault2,
() => response.Write("<title>Hutchtastic</title>"),
() => response.Write("<pre>"),
() => response.Write(wilson),
() => response.Write("</pre>"),
() => {
if (request.GET["flip"] == "crash") {
throw new ApplicationException("Wilson crashed!");
}
},
() => response.Write("<p><a href='" + href + "'>flip!</a></p>"),
() => response.Write("<p><a href='?flip=crash'>crash!</a></p>"),
complete));
}
catch (Exception ex) {
fault(ex);
}
});
};
}
示例15: Some2
public async Task Some2(Request req, Response res)
{
await res.Start();
await res.Write("SomeController.Index");
await res.Finish();
}