Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/config/optnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
OptHostIP = "host-ip"
OptMetricsEndpoint = "metrics-endpoint"
OptHeaders = "headers"
OptProxyAuthHeader = "proxy-auth-header"

// Normal options with CLI arguments
OptConcurrency = "concurrency"
Expand Down
15 changes: 12 additions & 3 deletions pkg/download/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ import (
"strings"

"github.com/rs/zerolog"
"github.com/spf13/viper"

"github.com/replicate/pget/pkg/client"
"github.com/replicate/pget/pkg/config"
"github.com/replicate/pget/pkg/logging"
)

type BufferMode struct {
Client client.HTTPClient
Options

queue *priorityWorkQueue
queue *priorityWorkQueue
redirected bool
}

func GetBufferMode(opts Options) *BufferMode {
client := client.NewHTTPClient(opts.Client)
m := &BufferMode{
Client: client,
Options: opts,
Client: client,
Options: opts,
redirected: false,
}
m.queue = newWorkQueue(opts.maxConcurrency(), m.chunkSize())
m.queue.start()
Expand Down Expand Up @@ -100,6 +104,7 @@ func (m *BufferMode) Fetch(ctx context.Context, url string) (io.Reader, int64, e
trueURL := firstChunkResp.Request.URL.String()
if trueURL != url {
logger.Info().Str("url", url).Str("redirect_url", trueURL).Msg("Redirect")
m.redirected = true
}

fileSize, err := m.getFileSizeFromResponse(firstChunkResp)
Expand Down Expand Up @@ -200,6 +205,10 @@ func (m *BufferMode) DoRequest(ctx context.Context, start, end int64, trueURL st
return nil, fmt.Errorf("failed to download %s: %w", trueURL, err)
}
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end))
proxyAuthHeader := viper.GetString(config.OptProxyAuthHeader)
Comment thread
NikhilSinha1 marked this conversation as resolved.
if proxyAuthHeader != "" && !m.redirected {
req.Header.Set("Authorization", proxyAuthHeader)
}
resp, err := m.Client.Do(req)
if err != nil {
return nil, fmt.Errorf("error executing request for %s: %w", req.URL.String(), err)
Expand Down
Loading