2

I have a handler which works as it should to serve a download. This is the important code:

    // Get size of file
    FileInfo f = new FileInfo(Settings.ReleaseFileLocation + ActualFileName);
    long FileSize = f.Length;

    // Init (returns ID of tblDownloadLog record created with blank end date)
    int DownloadRecordID = Constructor.VersionReleaseDownload.newReleaseDownload(ActualFileName);

    context.Response.Clear();
    context.Response.Buffer = false;        
    context.Response.ContentType = "application/octet-stream";
    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + OriginalFileName);
    context.Response.AddHeader("Content-Length", FileSize.ToString());
    context.Response.TransmitFile(Settings.ReleaseFileLocation + ActualFileName);
    context.Response.Close();               

    // Complete download log, fills out the end date
    Constructor.VersionReleaseDownload.completeReleaseDownload(DownloadRecordID);

The context.Response.Close(); ensures the completeReleaseDownload() only runs when the download is complete which is very useful (re Only count a download once it's served)

Problem is, we're getting a lot of logs that come from the same IP address in about the same time spacing. After digging a bit deeper it appears they are users using Download Resumer software.

When I try to use a download resumer it seems to fail. My question is:

  • How do I detect this is a partial request
  • How can I serve the partial request
  • How can I make it work with the above code so it a) Calls https://www.scirra.com/downloads/releases/construct2-r68-setup_4.exe on the first partial get and b) Calls completeReleaseDownload on the last partial get?
Community
  • 1
  • 1
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
  • I think this will answer to your question http://stackoverflow.com/questions/5429947/supporting-resumable-http-downloads-through-an-ashx-handler – Gregory Nozik Nov 17 '11 at 06:17

1 Answers1

2

This is achieved in Mime with an E-Tag, check out: http://www.devx.com/dotnet/Article/22533/1954

When you capture some packets sent using DownloadResumer, you will probably find the Range tag being specified.

Range: bytes=500-1000

This allows you to check if this is a partial request and if so, take action like:

bool isFirstRequest = RangeStart == 0;
bool isLastRequest =  RangeEnd  ==  file.TotalBytes - 1;//(Ranges use Zero-Based Indices)
Nkosi
  • 235,767
  • 35
  • 427
  • 472
Polity
  • 14,734
  • 2
  • 40
  • 40