capuchin r81 - in trunk: . src/libcapuchin/Downloaders
- From: sebp svn gnome org
- To: svn-commits-list gnome org
- Subject: capuchin r81 - in trunk: . src/libcapuchin/Downloaders
- Date: Sat, 29 Mar 2008 15:41:10 +0000 (GMT)
Author: sebp
Date: Sat Mar 29 15:41:10 2008
New Revision: 81
URL: http://svn.gnome.org/viewvc/capuchin?rev=81&view=rev
Log:
Added support for Content-Disposition in HttpDownloader
Modified:
trunk/ChangeLog
trunk/src/libcapuchin/Downloaders/HttpDownloader.cs
Modified: trunk/src/libcapuchin/Downloaders/HttpDownloader.cs
==============================================================================
--- trunk/src/libcapuchin/Downloaders/HttpDownloader.cs (original)
+++ trunk/src/libcapuchin/Downloaders/HttpDownloader.cs Sat Mar 29 15:41:10 2008
@@ -32,13 +32,24 @@
long fileSize = webResponse.ContentLength;
// Open the URL for download
strResponse = webResponse.GetResponseStream();
+
+ string disposition = webResponse.Headers.Get ("Content-Disposition").ToLower();
+ string localFile;
+ if (disposition.StartsWith ("attachment"))
+ {
+ // Looks like: Content-Disposition: attachment; filename=genome.jpeg;
+ string filename = disposition.Split (';')[1].Split('=')[1].Replace("\"", "");
+ localFile = Path.Combine( base.dl.Destination, filename);
+ } else {
+ localFile = Path.Combine( base.dl.Destination, Path.GetFileName(base.dl.Url) );
+ }
// Create a new file stream where we will be saving the data (local drive)
if (startPointInt == 0)
{
- strLocal = new FileStream(base.dl.LocalFile, FileMode.Create, FileAccess.Write, FileShare.None);
+ strLocal = new FileStream(localFile, FileMode.Create, FileAccess.Write, FileShare.None);
} else {
- strLocal = new FileStream(base.dl.LocalFile, FileMode.Append, FileAccess.Write, FileShare.None);
+ strLocal = new FileStream(localFile, FileMode.Append, FileAccess.Write, FileShare.None);
}
// It will store the current number of bytes we retrieved from the server
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]