Disable compression when downloading, otherwise HTTP client may do "decompression" on its own. #33

This commit is contained in:
Andrey Smirnov
2014-04-16 15:55:04 +04:00
parent cefc3cc2dc
commit 6352ce30ed

View File

@@ -28,6 +28,7 @@ type downloaderImpl struct {
unpause chan bool unpause chan bool
progress aptly.Progress progress aptly.Progress
threads int threads int
client *http.Client
} }
// downloadTask represents single item in queue // downloadTask represents single item in queue
@@ -50,6 +51,7 @@ func NewDownloader(threads int, progress aptly.Progress) aptly.Downloader {
unpause: make(chan bool), unpause: make(chan bool),
threads: threads, threads: threads,
progress: progress, progress: progress,
client: &http.Client{Transport: &http.Transport{DisableCompression: true}},
} }
for i := 0; i < downloader.threads; i++ { for i := 0; i < downloader.threads; i++ {
@@ -105,7 +107,7 @@ func (downloader *downloaderImpl) DownloadWithChecksum(url string, destination s
func (downloader *downloaderImpl) handleTask(task *downloadTask) { func (downloader *downloaderImpl) handleTask(task *downloadTask) {
downloader.progress.Printf("Downloading %s...\n", task.url) downloader.progress.Printf("Downloading %s...\n", task.url)
resp, err := http.Get(task.url) resp, err := downloader.client.Get(task.url)
if err != nil { if err != nil {
task.result <- err task.result <- err
return return