private async Task SendResponseMoveToIndex(OWINEnv env, CancellationToken cancel_token) { var content = System.Text.Encoding.UTF8.GetBytes("Moving..."); env.SetResponseHeader("Content-Type", "text/plain"); env.SetResponseHeader("Content-Length", content.Length.ToString()); env.SetResponseHeader("Location", "/html/index.html"); if (env.AccessControlInfo.AuthenticationKey != null) { env.SetResponseHeader("Set-Cookie", "auth=" + HTTPUtils.CreateAuthorizationToken(env.AccessControlInfo.AuthenticationKey)); } env.ResponseStatusCode = (int)HttpStatusCode.Moved; if (env.RequestMethod == "GET") { await env.ResponseBody.WriteAsync(content, 0, content.Length, cancel_token).ConfigureAwait(false); } }
private async Task SendResponseChannelList(OWINEnv env, CancellationToken cancel_token) { var channel_list = await GetYPChannels().ConfigureAwait(false); var contents = System.Text.Encoding.UTF8.GetBytes(ChannelsToIndex(channel_list)); env.SetResponseHeader("Content-Type", "text/plain;charset=utf-8"); env.SetResponseHeader("Content-Length", contents.Length.ToString()); if (env.AccessControlInfo.AuthenticationKey != null) { env.SetResponseHeader("Set-Cookie", "auth=" + HTTPUtils.CreateAuthorizationToken(env.AccessControlInfo.AuthenticationKey)); } if (env.RequestMethod == "GET") { await env.ResponseBody.WriteAsync(contents, 0, contents.Length, cancel_token).ConfigureAwait(false); } }
private async Task SendResponseFileContent(OWINEnv env, CancellationToken cancel_token) { var localpath = GetPhysicalPath(env); if (localpath == null) { throw new HTTPError(HttpStatusCode.Forbidden); } if (Directory.Exists(localpath)) { localpath = Path.Combine(localpath, "index.html"); if (!File.Exists(localpath)) { throw new HTTPError(HttpStatusCode.Forbidden); } } if (File.Exists(localpath)) { var contents = File.ReadAllBytes(localpath); var content_desc = GetFileDesc(Path.GetExtension(localpath)); env.SetResponseHeader("Content-Type", content_desc.MimeType); env.SetResponseHeader("Content-Length", contents.Length.ToString()); if (env.AccessControlInfo.AuthenticationKey != null) { env.SetResponseHeader("Set-Cookie", "auth=" + HTTPUtils.CreateAuthorizationToken(env.AccessControlInfo.AuthenticationKey)); } if (env.RequestMethod == "GET") { await env.ResponseBody.WriteAsync(contents, 0, contents.Length, cancel_token).ConfigureAwait(false); } } else { throw new HTTPError(HttpStatusCode.NotFound); } }