本文整理汇总了C#中HttpServer.SendBody方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.SendBody方法的具体用法?C# HttpServer.SendBody怎么用?C# HttpServer.SendBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer
的用法示例。
在下文中一共展示了HttpServer.SendBody方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
string command = request.UriPath;
if (command.StartsWith("/threadinfo"))
{
string board = request.QueryString["board"].Value;
string id = request.QueryString["id"].Value;
if (string.IsNullOrEmpty(board) || string.IsNullOrEmpty(id))
{
response.Redirect("/wjobs"); return true;
}
if (Program.active_dumpers.ContainsKey(board))
{
BoardWatcher bw = Program.active_dumpers[board];
int tid = 0;
Int32.TryParse(id, out tid);
if (bw.watched_threads.ContainsKey(tid))
{
ThreadWorker tw = bw.watched_threads[tid];
StringBuilder properties = new StringBuilder();
properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "Thread ID", tw.ID);
properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "Board", tw.Board.Board);
properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "Update Interval (in min)", tw.UpdateInterval);
properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "BumpLimit", tw.BumpLimit);
properties.AppendFormat("<span>{0}: </span><code>{1}</code><br/>", "ImageLimit", tw.ImageLimit);
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = "text/html";
byte[] data = Encoding.UTF8.GetBytes
(Properties.Resources.threadinfo_page
.Replace("{properties}", properties.ToString())
.Replace("{Logs}", get_logs(tw.Logs)));
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
return true;
}
}
response.Redirect("/wjobs"); return true;
}
return false;
}
示例2: _404
public static void _404(HttpServer.IHttpResponse response)
{
response.Status = System.Net.HttpStatusCode.NotFound;
byte[] d = System.Text.Encoding.UTF8.GetBytes("404");
response.ContentLength = d.Length;
response.SendHeaders();
response.SendBody(d);
}
示例3: write_text
public static void write_text(string text, HttpServer.IHttpResponse response)
{
byte[] data = Encoding.UTF8.GetBytes(text);
response.ContentType = ServerConstants.HtmlContentType;
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
}
示例4: WriteFinalHtmlResponse
protected void WriteFinalHtmlResponse(HttpServer.IHttpResponse response, string html)
{
byte[] data = Encoding.UTF8.GetBytes(html);
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = ServerConstants.HtmlContentType;
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
}
示例5: Process
//.........这里部分代码省略.........
page.Replace("{fq2s1o1c}", "");
page.Replace("{fq2s1o2c}", "");
page.Replace("{fq2s1o3c}", Selected);
break;
case Settings.FilePrioritizeModeEnum.LargerFirst:
page.Replace("{fq2s1o1c}", "");
page.Replace("{fq2s1o2c}", Selected);
page.Replace("{fq2s1o3c}", "");
break;
case Settings.FilePrioritizeModeEnum.SmallerFirst:
page.Replace("{fq2s1o1c}", Selected);
page.Replace("{fq2s1o2c}", "");
page.Replace("{fq2s1o3c}", "");
break;
default:
break;
}
*/
if (Settings.AutoRemoveCompleteFiles)
{
page.Replace("{fq3c}", Checked);
}
else
{
page.Replace("{fq3c}", "");
}
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = "text/html";
byte[] data = Encoding.UTF8.GetBytes(page.ToString());
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
return true;
}
if (command.StartsWith("/settings/"))
{
// -------------- General Settings ------------
Settings.AutoStartManuallyAddedThreads = request.QueryString["gs0"].Value == "1";
Settings.ThumbnailOnly = request.QueryString["gs1"].Value == "1";
Settings.EnableFileStats = request.QueryString["gs2"].Value == "1";
Settings.UseHttps = request.QueryString["gs3"].Value == "1";
Settings.RemoveThreadsWhenTheyEnterArchivedState = request.QueryString["gs4"].Value == "1";
Settings.SaveBannedFileThumbnail = request.QueryString["gs5"].Value == "1";
Settings.CacheAPIFilesInMemory = request.QueryString["gs6"].Value == "1";
if (Settings.EnableFileStats) { FileSystemStats.Init(); }
// -------------- Security Settings ------------
Settings.EnableAuthentication = request.QueryString["ss0"].Value == "1";
Settings.AllowGuestAccess = request.QueryString["ss1"].Value == "1";
Settings.AuthUsername = request.QueryString["ba_user"].Value;
Settings.AuthPassword = request.QueryString["ba_pass"].Value;
// -------------- FFMPEG Settings ------------
Settings.ConvertGifsToWebm = request.QueryString["ff0"].Value == "1";
Settings.ConvertWebmToMp4 = request.QueryString["ff1"].Value == "1";
Settings.Convert_Webmgif_To_Target = request.QueryString["ff2"].Value == "1";
if (request.QueryString["ff2s1"].Value == "gif")
{
示例6: Process
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
string command = request.UriPath;
if (command.StartsWith("/fileinfo/"))
{
string[] a = command.Split('/');
if (a.Length >= 3)
{
string filehash = a[2];
FileQueueStateInfo fqs = Program.get_file_state(filehash);
if (fqs != null)
{
StringBuilder page = new StringBuilder(Properties.Resources.fileinfo);
page.Replace("{fullfilelink}", string.Format("/file/{0}.{1}", fqs.Hash, fqs.Ext));
page.Replace("{thumbsource}", string.Format("/thumb/{0}.jpg", fqs.Hash));
page.Replace("{url}", fqs.Url);
page.Replace("{p}", fqs.Percent().ToString());
page.Replace("{md5}", fqs.Hash);
page.Replace("{name}", fqs.FileName);
page.Replace("{workid}", filehash);
page.Replace("{jtype}", fqs.Type.ToString());
page.Replace("{rcount}", fqs.RetryCount.ToString());
page.Replace("{downloaded}", Program.format_size_string(fqs.Downloaded));
page.Replace("{length}", Program.format_size_string(fqs.Length));
page.Replace("{Logs}", get_logs(fqs.Logs));
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = "text/html";
byte[] data = Encoding.UTF8.GetBytes(page.ToString());
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
return true;
}
else
{
response.Redirect("/fq");
return true;
}
}
}
return false;
}
示例7: Process
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
string command = request.UriPath.ToString();
if (command.StartsWith("/file/"))
{
string[] e = command.Split('/').Last().Split('.');
if (e.Length != 2)
return false;
string hash = e[0];
string extension = e[1];
string path = FileOperations.MapFullFile(hash, extension);
string ua = request.Headers["User-Agent"].ToLower();
bool no_webm = device_not_support_webm(ua);
FileInfo fi = new FileInfo(path);
if (fi.Exists && fi.DirectoryName.Contains(Program.file_save_dir))
{
#region WebM to MP4
if (extension == "webm" && Settings.ConvertWebmToMp4)
{
if (File.Exists(Program.ffmpeg_path) && no_webm)
{
//convert the video for the user
ProcessStartInfo psr = new System.Diagnostics.ProcessStartInfo(Program.ffmpeg_path);
string temp_path = Path.Combine(Program.temp_files_dir, "con-" + hash + ".mp4");
File.Delete(temp_path);
psr.CreateNoWindow = true;
psr.UseShellExecute = false;
psr.Arguments = string.Format("-y -i \"{0}\" -c:v libx264 -preset ultrafast -vf scale=320:240 -threads 2 \"{1}\"", path, temp_path);
psr.RedirectStandardOutput = true;
using (Process proc = System.Diagnostics.Process.Start(psr))
{
proc.WaitForExit(20000);
if (!proc.HasExited) { proc.Kill(); }
}
if (File.Exists(temp_path))
{
byte[] converted_data = File.ReadAllBytes(temp_path);
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = "video/mpeg";
response.ContentLength = converted_data.Length;
response.AddHeader("content-disposition", string.Format("inline; filename=\"{0}\"", hash + ".mp4"));
response.SendHeaders();
response.SendBody(converted_data);
File.Delete(temp_path);
return true;
}
}
} // webm to mp4 check
#endregion
response.ContentType = get_mime(extension);
response.Status = System.Net.HttpStatusCode.OK;
byte[] data = File.ReadAllBytes(path);
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
return true;
}
// probably this gif file has been converted to a webm
else if (File.Exists(path + ".webm") && fi.DirectoryName.Contains(Program.file_save_dir))
{
string was_gif_path = path + ".webm";
if (Settings.Convert_Webmgif_To_Target /*the general switch to gif to x*/ &&
(!Settings.Convert_Webmgif_only_devices || (Settings.Convert_Webmgif_only_devices && no_webm)))
{
if (File.Exists(Program.ffmpeg_path))
{
ProcessStartInfo psr = new System.Diagnostics.ProcessStartInfo(Program.ffmpeg_path)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
};
string temp_path = "";
if (Settings.Convert_Webmgif_Target == Settings.X_Target.GIF)
{
//.........这里部分代码省略.........
示例8: Process
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
string command = request.UriPath.ToString();
if (command == "/favicon.ico")
{
response.Status = System.Net.HttpStatusCode.OK;
response.ContentLength = Properties.Resources.favicon_ico.Length;
response.ContentType = "image/x-icon";
response.SendHeaders();
response.SendBody(Properties.Resources.favicon_ico);
return true;
}
if (command.StartsWith("/res/"))
{
byte[] data = null;
switch (command.Split('/')[2].ToLower())
{
case "bgwhite.png":
data = Properties.Resources.bgwhite;
response.ContentType = "image/png";
break;
case "hr.png":
data = Properties.Resources.hr;
response.ContentType = "image/png";
break;
case "locked.png":
data = Properties.Resources.locked;
response.ContentType = "image/png";
break;
case "sticky.png":
data = Properties.Resources.sticky;
response.ContentType = "image/png";
break;
case "bootstrap.css":
//data = Encoding.UTF8.GetBytes(Properties.Resources.bootstrap_css);
data = Properties.Resources.paper_theme_min;
response.ContentType = "text/css";
break;
case "dashboard.css":
data = Encoding.UTF8.GetBytes(Properties.Resources.dashboard_css);
response.ContentType = "text/css";
break;
case "bootstrap.js":
data = Encoding.UTF8.GetBytes(Properties.Resources.bootstrap_js);
response.ContentType = "application/javascript";
break;
case "jquery.js":
data = Encoding.UTF8.GetBytes(Properties.Resources.jquery_js);
response.ContentType = "application/javascript";
break;
case "docs.js":
data = Encoding.UTF8.GetBytes(Properties.Resources.docs_js);
response.ContentType = "application/javascript";
break;
case "css.css":
data = Encoding.UTF8.GetBytes(ChanArchiver.Properties.Resources.layout);
response.ContentType = "text/css";
break;
case "blue.css":
data = Encoding.UTF8.GetBytes(ChanArchiver.Properties.Resources.css_blue);
response.ContentType = "text/css";
break;
case "favicon.ico":
data = Properties.Resources.favicon_ico;
response.ContentType = "image/x-icon";
break;
case "jquery.flot.min.js":
data = Encoding.UTF8.GetBytes(Properties.Resources.jquery_flot_min);
response.ContentType = "application/javascript";
break;
case "jquery.flot.categories.min.js":
data = Encoding.UTF8.GetBytes(Properties.Resources.jquery_flot_categories_min);
response.ContentType = "application/javascript";
break;
case "jquery.flot.pie.min.js":
data = Properties.Resources.jquery_flot_pie_min;
response.ContentType = "application/javascript";
break;
case "sorttable.js":
data = Properties.Resources.sorttable_js;
response.ContentType = "application/javascript";
break;
//webfonts
case "font-awesome.min.css":
data = Properties.Resources.font_awesome_min;
response.ContentType = "text/css";
break;
case "fontawesome-webfont.eot":
data = Properties.Resources.fontawesome_webfont_eot;
response.ContentType = "application/vnd.ms-fontobject";
break;
case "fontawesome-webfont.svg":
data = Properties.Resources.fontawesome_webfont_svg;
response.ContentType = "image/svg+xml";
break;
case "fontawesome-webfont.ttf":
case "fontawesome-webfont.ttf?v=4.1.0":
//.........这里部分代码省略.........
示例9: Process
//.........这里部分代码省略.........
int limit = 250;
string limit_user = request.QueryString["limit"].Value;
if (!string.IsNullOrEmpty(limit_user))
{
Int32.TryParse(request.QueryString["limit"].Value, out limit);
}
StringBuilder sb = new StringBuilder();
string filter = "blank";
string prev_value = request.QueryString["prev_value"].Value;
string next_value = "";
if (!(selector_index < 0 || selector_index > 4))
{
switch (selector_index)
{
case 0:
case 1:
filter = "*.webm"; break;
case 2:
filter = "*.jpg"; break;
case 3:
filter = "*.png"; break;
case 4:
filter = "*.gif"; break;
default: break;
}
var fc = Selectors[selector_index];
int counter = 0;
bool has_reached_next_page = false;
has_reached_next_page = string.IsNullOrEmpty(prev_value);
foreach (string path in FileOperations.EnumerateOptimizedDirectory(Program.file_save_dir))
{
string filename = System.IO.Path.GetFileName(path);
if (has_reached_next_page)
{
if (counter > limit) { next_value = filename; break; }
if (fc(filename))
{
string file_name_without_extension = System.IO.Path.GetFileNameWithoutExtension(filename);
string ext = System.IO.Path.GetExtension(filename);
sb.AppendFormat("<a href=\"/file/{0}{1}\"><img src=\"/thumb/{0}.jpg\" /></a><br />",
file_name_without_extension, ext);
counter++;
}
}
else
{
has_reached_next_page = prev_value == filename;
}
}
}
StringBuilder page = new StringBuilder(Properties.Resources.file_list_page);
for (int i = 0; i < 4; i++)
{
if (i == selector_index)
{
page.Replace("{o" + i.ToString() + "}", "selected='selected'");
}
else
{
page.Replace("{o" + i.ToString() + "}", "");
}
}
page//.Replace("{prev}", prev_value)
.Replace("{next}", next_value)
.Replace("{ftvalue}", filter)
.Replace("{lvalue}", limit.ToString())
.Replace("{items}", sb.ToString());
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = "text/html";
byte[] data = Encoding.UTF8.GetBytes(page.ToString());
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
return true;
}
return false;
}
示例10: Process
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
if (request.UriPath.StartsWith(Url))
{
string board = request.QueryString[UrlParameters.Board].Value;
string threadIdStr = request.QueryString[UrlParameters.ThreadId].Value;
int threadId = -1;
int.TryParse(threadIdStr, out threadId);
if (!Program.IsBoardLetterValid(board))
{
ThreadServerModule.write_text("Invalid board letter", response);
return true;
}
if (threadId <= 0)
{
ThreadServerModule.write_text("Invalid thread id", response);
return true;
}
PostFormatter[] thread_data = ThreadStore.GetStorageEngine().GetThread(board, threadIdStr);
MemoryStream memIO = new MemoryStream();
ZipOutputStream zipStream = new ZipOutputStream(memIO);
zipStream.SetLevel(0); // no compression is needed since most of the files are media files, and they are already compressed anyway
write_file_to_zip(zipStream, "res/blue.css", Encoding.UTF8.GetBytes(Properties.Resources.css_blue));
write_file_to_zip(zipStream, "res/sticky.png", Properties.Resources.sticky);
write_file_to_zip(zipStream, "res/locked.png", Properties.Resources.locked);
foreach (PostFormatter pf in thread_data)
{
if (pf.MyFile != null)
{
string full_path;
if (FileOperations.ResolveFullFilePath(pf.MyFile.Hash, pf.MyFile.Extension, out full_path))
{
string ext = Path.GetExtension(full_path);
if (!string.IsNullOrEmpty(ext))
{
ext = ext.Substring(1);
}
if (ext != pf.MyFile.Extension)
{
pf.MyFile.ChangeExtension(ext);
}
string zip_file_name = string.Format("file/{0}.{1}", pf.MyFile.Hash, ext);
byte[] data = File.ReadAllBytes(full_path);
pf.MyFile.Size = data.Length;
write_file_to_zip(zipStream, zip_file_name, data);
}
string thumb_path;
if (FileOperations.CheckThumbFileExist(pf.MyFile.Hash, out thumb_path))
{
string zip_file_name = string.Format("thumb/{0}.jpg", pf.MyFile.Hash);
write_file_to_zip(zipStream, zip_file_name, File.ReadAllBytes(thumb_path));
}
}
}
string notes = ThreadStore.GetStorageEngine().GetThreadNotes(board, threadId);
string pageHtml = build_page_html(board, threadIdStr, thread_data, notes);
write_file_to_zip(zipStream, "index.html", Encoding.UTF8.GetBytes(pageHtml));
zipStream.Close();
memIO.Close();
byte[] result = memIO.ToArray();
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = ServerConstants.ZipContentType;
response.ContentLength = result.Length;
response.AddHeader("content-disposition", string.Format("attachment; filename=\"{0}.zip\"", threadId));
response.SendHeaders();
response.SendBody(result);
return true;
}
return false;
}
示例11: Process
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
string command = request.UriPath.ToString();
if (command.StartsWith("/logs/"))
{
string[] a = command.Split('/');
if (a.Length >= 3)
{
string mode = a[2];
string id = a[3];
LogEntry[] data = null;
switch (mode)
{
case "file":
FileQueueStateInfo st = Program.get_file_state(id);
if (st != null)
{
data = st.Logs;
}
break;
case "threadworker": // /logs/threadworker/board/tid
if (Program.active_dumpers.ContainsKey(id))
{
BoardWatcher bw = Program.active_dumpers[id];
if (bw.watched_threads.ContainsKey(Convert.ToInt32(a[4])))
{
data = bw.watched_threads[Convert.ToInt32(a[4])].Logs;
}
}
break;
case "boardwatcher":
if (Program.active_dumpers.ContainsKey(id))
{
BoardWatcher bw = Program.active_dumpers[id];
data = bw.Logs;
}
break;
default:
break;
}
if (data != null)
{
StringBuilder items = new StringBuilder();
for (int index = 0; index < data.Length; index++)
{
try
{
LogEntry e = data[index];
items.Append("<tr>");
switch (e.Level)
{
case LogEntry.LogLevel.Fail:
items.Append("<td><span class=\"label label-danger\">Fail</span></td>");
break;
case LogEntry.LogLevel.Info:
items.Append("<td><span class=\"label label-info\">Info</span></td>");
break;
case LogEntry.LogLevel.Success:
items.Append("<td><span class=\"label label-success\">Success</span></td>");
break;
case LogEntry.LogLevel.Warning:
items.Append("<td><span class=\"label label-warning\">Warning</span></td>");
break;
default:
items.Append("<td><span class=\"label label-default\">Unknown</span></td>");
break;
}
items.AppendFormat("<td>{0}</td>", e.Time);
items.AppendFormat("<td>{0}</td>", e.Title);
items.AppendFormat("<td>{0}</td>", e.Sender);
items.AppendFormat("<td>{0}</td>", e.Message);
items.Append("</tr>");
}
catch (Exception) { continue; }
}
//write everything
response.Status = System.Net.HttpStatusCode.OK;
response.ContentType = "text/html";
byte[] fdata = Encoding.UTF8.GetBytes(Properties.Resources.logs_page.Replace("{Logs}", items.ToString()));
response.ContentLength = fdata.Length;
response.SendHeaders();
response.SendBody(fdata);
//.........这里部分代码省略.........
示例12: Process
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
{
string command = request.UriPath.ToString();
#region Thread & Index View
if (command.StartsWith("/boards/"))
{
response.Encoding = System.Text.Encoding.UTF8;
string[] parame = command.Split('?')[0].Split('/');
if (parame.Length == 3)
{
//board index view mode
string board = parame[2]; if (string.IsNullOrEmpty(board))
{
response.Redirect("/boards");
return true;
}
ThreadStore.GetStorageEngine().UpdateThreadStoreStats();
int board_thread_count = ThreadStore.GetStorageEngine().StoreStats[board];
if (board_thread_count == 0)
{
response.Redirect("/boards");
return true;
}
int rem = (board_thread_count % ThreadPerPage);
int page_count = ((board_thread_count - rem) / ThreadPerPage) + (rem > 0 ? 1 : 0);
if (page_count <= 0) { page_count = 1; }
int page_offset = 0;
Int32.TryParse(request.QueryString["pn"].Value, out page_offset); page_offset = Math.Abs(page_offset);
int start = page_offset * (ThreadPerPage);
PostFormatter[] board_index = ThreadStore.GetStorageEngine().GetIndex(board, start, ThreadPerPage);
StringBuilder s = new StringBuilder();
foreach (var pf in board_index)
{
s.Append("<div class='row'>");
s.Append
(
pf.ToString()
.Replace("{post:link}", string.Format("/boards/{0}/{1}", board, pf.PostID))
);
s.Append("</div>");
}
StringBuilder page_numbers = new StringBuilder();
for (int i = 0; i < page_count; i++)
{
if (i == page_offset)
{
page_numbers.AppendFormat("<li class=\"active\"><a href=\"?pn={0}\">{1}</a></li>", i, i + 1);
}
else
{
page_numbers.AppendFormat("<li><a href=\"?pn={0}\">{1}</a></li>", i, i + 1);
}
}
byte[] data = Encoding.UTF8.GetBytes(
Properties.Resources.board_index_page
.Replace("{po}", Convert.ToString(page_offset == 0 ? 0 : page_offset - 1))
.Replace("{no}", Convert.ToString(page_offset == page_count - 1 ? page_count : page_offset + 1))
.Replace("{pagen}", page_numbers.ToString())
.Replace("{Items}", s.ToString()));
response.ContentType = ServerConstants.HtmlContentType;
response.Encoding = Encoding.UTF8;
response.Status = System.Net.HttpStatusCode.OK;
response.ContentLength = data.Length;
response.SendHeaders();
response.SendBody(data);
return true;
}
else if (parame.Length >= 4)
{
//thread view mode
string board = parame[2];
string threadid = parame[3];
int parsedThreadId = -1;
int.TryParse(threadid, out parsedThreadId);
if (string.IsNullOrEmpty(board) || string.IsNullOrEmpty(threadid)) { _404(response); return true; }
if (parsedThreadId <= 0) { _404(response); return true; }
//.........这里部分代码省略.........