Thanks for the code.
I am already doing something very similar to this. It works fine for things like PDFs and word documents.
If I try downloading applications it seems to turn the exes into dos exes and winzip files into something unusable.
If I link to the files directly without using content encoding the files are fine.
Normal users can't do this because the directory is protected.
So I must be doing something wrong with the content encoding but from my looks here and in other threads I can't figure it out.
If I can't get content encoding to work, the linking to the file directory with a header with the username/password passed in somehow is the only alternative I can think of.