Skip to content

Commit

Permalink
set/unset CheckRedirect in cmd.getState
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Aug 21, 2024
1 parent 3b56758 commit a7a81dc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions getparty.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,6 @@ func (cmd *Cmd) Run(args []string, version, commit string) (err error) {
client := &http.Client{
Transport: rtBuilder.pool(cmd.opt.Parts > 1).build(),
Jar: jar,
CheckRedirect: func(_ *http.Request, via []*http.Request) error {
max := int(cmd.opt.MaxRedirect)
if max != 0 && len(via) > max {
return errors.WithMessage(ErrMaxRedirect, "Stopping")
}
return http.ErrUseLastResponse
},
}
session, err := cmd.getState(client)
if err != nil {
Expand Down Expand Up @@ -274,7 +267,6 @@ func (cmd *Cmd) Run(args []string, version, commit string) (err error) {
sleep := time.Duration(cmd.opt.SpeedLimit*60) * time.Millisecond
single := len(session.Parts) == 1
cancelMap := make(map[int]func())
client.CheckRedirect = nil

for i, p := range session.Parts {
p.order = i + 1
Expand Down Expand Up @@ -415,6 +407,16 @@ func (cmd Cmd) getTLSConfig() (*tls.Config, error) {
}

func (cmd Cmd) getState(client *http.Client) (session *Session, err error) {
client.CheckRedirect = func(_ *http.Request, via []*http.Request) error {
max := int(cmd.opt.MaxRedirect)
if max != 0 && len(via) > max {
return errors.WithMessage(ErrMaxRedirect, "Stopping")
}
return http.ErrUseLastResponse
}
defer func() {
client.CheckRedirect = nil
}()
for {
switch {
case cmd.opt.SessionName != "":
Expand Down

0 comments on commit a7a81dc

Please sign in to comment.