1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
22
|***************************************************************************/
32
namespace iFolder.WebService
35
/// File Download Handler
37
public class DownloadHandler : FileHandler
39
const int BUFFERSIZE = (64 * 1024);
44
public DownloadHandler() : base()
48
#region IHttpHandler Members
51
/// Process the Request
53
/// <param name="context">The HttpContext object.</param>
54
public override void ProcessRequest(HttpContext context)
64
string id = ((entryID != null) && (entryID.Length != 0)) ? entryID : entryPath;
65
throw new EntryDoesNotExistException(id);
69
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
74
context.Response.Clear();
75
context.Response.AddHeader("Content-Disposition",
76
String.Format("attachment; filename=\"{0}\"",
77
HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8).Replace("+", "%20")));
78
context.Response.AddHeader("Content-Length", stream.Length.ToString());
79
context.Response.ContentType = "application/octet-stream";
80
context.Response.BufferOutput = false;
82
Stream output = context.Response.OutputStream;
84
byte[] buffer = new byte[BUFFERSIZE];
87
while((count = stream.Read(buffer, 0, BUFFERSIZE)) > 0)
89
output.Write(buffer, 0, count);
94
log.LogAccess("Download", node.GetRelativePath(), node.ID, "Success");
99
log.LogAccess("Download", node.GetRelativePath(), node.ID, "Failed");
111
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
112
context.Response.StatusDescription = e.GetType().Name;