···5858 // defaults to the current working directory.
5959 OutputDir string
60606161- // client is the HTTP client used for every request needed to download all
6262- // the files.
6363- client *http.Client
6161+ // Client is the HTTP client used for all requests. It uses a customized
6262+ // HTTP transport and timeout to handle content ranges download and
6363+ // parallel requests to the same server. Check NewHTTPClient for
6464+ // customizing it.
6565+ Client *http.Client
64666567 // TimeoutPerChunk is the timeout for the download of each chunk from each
6668 // URL. A chunk is a part of a file requested using the content range HTTP
···103105 return nil, fmt.Errorf("error creating the request for %s: %w", u, err)
104106 }
105107 req.Header.Set("Range", c.rangeHeader())
106106- resp, err := d.client.Do(req)
108108+ resp, err := d.Client.Do(req)
107109 if err != nil {
108110 return nil, fmt.Errorf("error sending a get http request to %s: %w", u, err)
109111 }
···154156 if err != nil {
155157 return fmt.Errorf("creating the request for %s: %w", u, err)
156158 }
157157- resp, err := d.client.Do(req)
159159+ resp, err := d.Client.Do(req)
158160 if err != nil {
159161 return fmt.Errorf("dispatching the request for %s: %w", u, err)
160162 }
···277279// DownloadWithContext is a version of Download that takes a context. The
278280// context can be used to stop all downloads in progress.
279281func (d *Downloader) DownloadWithContext(ctx context.Context, urls ...string) <-chan DownloadStatus {
280280- if d.client == nil {
281281- d.client = newClient(d.ConcurrencyPerServer, d.Timeout)
282282+ if d.Client == nil {
283283+ d.Client = newClient(d.ConcurrencyPerServer, d.Timeout)
282284 }
283285 ch := make(chan DownloadStatus, 2*len(urls)) // the first status will be the total file size (and or an error creating/trucating the file).
284286 var wg sync.WaitGroup // this wait group is used to wait for all chunks (from all downloads) to finish.
···317319 MaxRetries: DefaultMaxRetries,
318320 ChunkSize: DefaultChunkSize,
319321 WaitRetry: DefaultWaitRetry,
320320- client: newClient(DefaultMaxRetries, DefaultTimeout),
322322+ Client: newClient(DefaultMaxRetries, DefaultTimeout),
321323 }
322324}
323325···325327 t := http.DefaultTransport.(*http.Transport).Clone()
326328 t.MaxConnsPerHost = maxParallelDownloadsPerServer
327329 t.MaxIdleConnsPerHost = maxParallelDownloadsPerServer
330330+328331 return &http.Client{
329332 Timeout: timeoutPerChunk,
330333 Transport: t,