private static AppFunc Fail(int status, string body, string headerName = null, string headerValue = null) { return env => { Request request = new Request(env); Response response = new Response(env); response.StatusCode = status; response.Headers .SetHeader("Content-Type", "text/plain") .SetHeader("Content-Length", body.Length.ToString(CultureInfo.InvariantCulture)) .SetHeader("X-Cascade", "pass"); if (headerName != null && headerValue != null) { response.Headers.SetHeader(headerName, headerValue); } if ("HEAD".Equals(request.Method, StringComparison.OrdinalIgnoreCase)) { return TaskHelpers.Completed(); } return response.WriteAsync(body); }; }
public static Task Call(IDictionary<string, object> env) { Response response = new Response(env) { StatusCode = 404, ReasonPhrase = "Not Found", ContentType = "text/html", ContentLength = body.Length, }; if ("HEAD".Equals(new Request(env).Method, StringComparison.OrdinalIgnoreCase)) { return TaskHelpers.Completed(); } return response.WriteAsync(body); }