private static async Task<Response> ExecuteCore(IEdgePage page, Request request, ITrace tracer) { Response resp = new Response(200); resp.Start(); await page.Run(request, resp); resp.End(); return resp; }
Task NewServerCallback(IDictionary<string, object> env) { var path = (string)env[OwinConstants.RequestPath]; Tracing.Info(path); if (!content.IsAvailable(path)) { var path404 = "/404.html"; var use404 = content.IsAvailable(path404); var response = new Response(env) { ContentType = use404 ? path404.MimeType() : path.MimeType() }; using (var writer = new StreamWriter(response.OutputStream)) { if (use404) { writer.Write(content.GetContent(path404)); } else { writer.Write("Page not found: " + path); } } return TaskHelpers.Completed(); } if (path.MimeType().IsBinaryMime()) { var fileContents = content.GetBinaryContent(path); var response = new Response(env) { ContentType = path.MimeType() }; response.Headers["Content-Range"] = new[] { string.Format("bytes 0-{0}", (fileContents.Length - 1)) }; response.Headers["Content-Length"] = new[] { fileContents.Length.ToString(CultureInfo.InvariantCulture) }; response.Write(new ArraySegment<byte>(fileContents)); } else if (content.IsDirectory(path) && !path.EndsWith("/")) { //if path is a directory without trailing slash, redirects to the same url with a trailing slash var response = new Response(env) { Status = "301 Moved Permanently" }; response.Headers["Location"] = new[] { String.Format("http://localhost:{0}{1}/", Port, path) }; } else { var response = new Response(env) { ContentType = path.MimeType() }; using (var writer = new StreamWriter(response.OutputStream)) { writer.Write(content.GetContent(path)); } } return TaskHelpers.Completed(); }
private static AppDelegate ProcessRequest(AppDelegate next, Regex regex, string method, Action<RoutedRequest, Response> app) { return (env, result, fault) => { var path = (string)env["owin.RequestPath"]; if (path.EndsWith("/")) path = path.TrimEnd('/'); if ((string)env["owin.RequestMethod"] == method && regex.IsMatch(path)) { var req = new RoutedRequest(env, regex, path); var res = new Response(result); app(req, res); } else { next(env, result, fault); } }; }
public ResponseWriter(Response response) { Response = response; }
private static bool TryValidateResult(IDictionary<string, object> env, IList<string> warnings) { var resp = new Response(env); IDictionary<string, string[]> responseHeaders = resp.Headers; // Headers if (!TryValidateHeaderCollection(env, responseHeaders, "Response", warnings)) { return false; } // Status code object temp; if (env.TryGetValue("owin.ResponseStatusCode", out temp)) { if (temp == null) { SetFatalResult(env, "3.2.2", "The response status code value is null"); return false; } if (!(temp is int)) { SetFatalResult(env, "3.2.2", "Status code is not an int: " + temp.GetType().FullName); return false; } int statusCode = (int)temp; if (statusCode <= 100 || statusCode >= 1000) { SetFatalResult(env, "3.2.2", "Invalid status code value: " + statusCode); return false; } } // Reason phrase if (env.TryGetValue("owin.ResponseReasonPhrase", out temp)) { if (temp == null) { SetFatalResult(env, "3.2.2", "The reason phrase value is null"); return false; } if (!(temp is string)) { SetFatalResult(env, "3.2.2", "The reason phrase is not a string: " + temp.GetType().FullName); return false; } } // Protocol if (env.TryGetValue("owin.ResponseProtocol", out temp)) { if (temp == null) { SetFatalResult(env, "3.2.2", "The response protocol value is null"); return false; } if (!(temp is string)) { SetFatalResult(env, "3.2.2", "The response protocol is not a string: " + temp.GetType().FullName); return false; } string protocol = (string)temp; if (!protocol.Equals("HTTP/1.1", StringComparison.OrdinalIgnoreCase) && !protocol.Equals("HTTP/1.0", StringComparison.OrdinalIgnoreCase)) { warnings.Add(CreateWarning("3.2.2", "Unrecognized response protocol: " + protocol)); } } return true; }
/// <summary> /// Queries sent from the client end up here /// </summary> /// <param name="env"></param> /// <param name="result"></param> /// <param name="fault"></param> private void ServerCallback(IDictionary<string, object> env, ResultDelegate result, Action<Exception> fault) { string requestString = (string)env[OwinConstants.RequestPath]; Tracing.Info(requestString); var request = new Gate.Request(env); var response = new Gate.Response(result); if (!content.IsAvailable(requestString)) { // File not found SendText(result, env, "Page not found: " + requestString); return; } else { // Send page back if (requestString.MimeType().IsBinaryMime()) { byte[] fileContents = content.GetBinaryContent(requestString); SendData(result, env, fileContents); } else { string fileContents = content.GetContent(requestString); SendText(result, env, fileContents); } return; } }
internal ServerResponse(Request request, Response response) { _request = request; _response = response; _cancellationToken = request.CallDisposed; }
public ResponseStream(Response response) { _response = response; }
public ResponseWrapper(Response response) { _response = response; }