本文整理汇总了C#中HttpServer.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.AddHeader方法的具体用法?C# HttpServer.AddHeader怎么用?C# HttpServer.AddHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer
的用法示例。
在下文中一共展示了HttpServer.AddHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
//.........这里部分代码省略.........
示例2: 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;
}