本文整理汇总了C#中HttpServer.HttpServer.SendHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.SendHeaders方法的具体用法?C# HttpServer.SendHeaders怎么用?C# HttpServer.SendHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer.HttpServer
的用法示例。
在下文中一共展示了HttpServer.SendHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadBugReport
private void DownloadBugReport(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
long id;
long.TryParse(input["id"].Value, out id);
var tf = Program.DataConnection.GetTempFiles().Where(x => x.ID == id).FirstOrDefault();
if (tf == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
if (!System.IO.File.Exists(tf.Path))
{
ReportError(response, bw, "File is missing");
return;
}
var filename = "bugreport.zip";
using(var fs = System.IO.File.OpenRead(tf.Path))
{
response.ContentLength = fs.Length;
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
response.ContentType = "application/octet-stream";
bw.SetOK();
response.SendHeaders();
fs.CopyTo(response.Body);
response.Send();
}
}
示例2: ExportBackup
private void ExportBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var bk = Program.DataConnection.GetBackup(input["id"].Value);
if (bk == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
var cmdline = Library.Utility.Utility.ParseBool(input["cmdline"].Value, false);
if (cmdline)
{
bw.OutputOK(new { Command = Runner.GetCommandLine(Runner.CreateTask(DuplicatiOperation.Backup, bk)) });
}
else
{
var passphrase = input["passphrase"].Value;
var scheduleId = Program.DataConnection.GetScheduleIDsFromTags(new string[] { "ID=" + bk.ID });
var ipx = new ImportExportStructure() {
CreatedByVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
Backup = (Database.Backup)bk,
Schedule = (Database.Schedule)(scheduleId.Any() ? Program.DataConnection.GetSchedule(scheduleId.First()) : null),
DisplayNames = GetSourceNames(bk)
};
byte[] data;
using(var ms = new System.IO.MemoryStream())
using(var sw = new System.IO.StreamWriter(ms))
{
Serializer.SerializeJson(sw, ipx, true);
if (!string.IsNullOrWhiteSpace(passphrase))
{
ms.Position = 0;
using(var ms2 = new System.IO.MemoryStream())
using(var m = new Duplicati.Library.Encryption.AESEncryption(passphrase, new Dictionary<string, string>()))
{
m.Encrypt(ms, ms2);
data = ms2.ToArray();
}
}
else
data = ms.ToArray();
}
var filename = Library.Utility.Uri.UrlEncode(bk.Name) + "-duplicati-config.json";
if (!string.IsNullOrWhiteSpace(passphrase))
filename += ".aes";
response.ContentLength = data.Length;
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
response.ContentType = "application/octet-stream";
bw.SetOK();
response.SendHeaders();
response.SendBody(data);
}
}
示例3: ExportBackup
private void ExportBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
{
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
var bk = Program.DataConnection.GetBackup(input["id"].Value);
if (bk == null)
{
ReportError(response, bw, "Invalid or missing backup id");
return;
}
var cmdline = Library.Utility.Utility.ParseBool(input["cmdline"].Value, false);
if (cmdline)
{
bw.OutputOK(new { Command = Runner.GetCommandLine(Runner.CreateTask(DuplicatiOperation.Backup, bk)) });
}
else
{
var passphrase = input["passphrase"].Value;
var ipx = Program.DataConnection.PrepareBackupForExport(bk);
byte[] data;
using(var ms = new System.IO.MemoryStream())
using(var sw = new System.IO.StreamWriter(ms))
{
Serializer.SerializeJson(sw, ipx, true);
if (!string.IsNullOrWhiteSpace(passphrase))
{
ms.Position = 0;
using(var ms2 = new System.IO.MemoryStream())
using(var m = new Duplicati.Library.Encryption.AESEncryption(passphrase, new Dictionary<string, string>()))
{
m.Encrypt(ms, ms2);
data = ms2.ToArray();
}
}
else
data = ms.ToArray();
}
var filename = Library.Utility.Uri.UrlEncode(bk.Name) + "-duplicati-config.json";
if (!string.IsNullOrWhiteSpace(passphrase))
filename += ".aes";
response.ContentLength = data.Length;
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
response.ContentType = "application/octet-stream";
bw.SetOK();
response.SendHeaders();
response.SendBody(data);
}
}