Fix redoing redirect response raft snapshot cli (#8211)

* Fix redoing redirect response raft snapshot cli

* Removed unnecessary lines of code

* go mod vendor
This commit is contained in:
Michel Vocks 2020-01-27 11:25:52 +01:00 committed by GitHub
parent efb2152759
commit 90f1d3813d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package api
import (
"context"
"fmt"
"io"
"net/http"
@ -95,6 +96,29 @@ func (c *Sys) RaftSnapshot(snapWriter io.Writer) error {
return nil
}
// Check for a redirect, only allowing for a single redirect
if resp.StatusCode == 301 || resp.StatusCode == 302 || resp.StatusCode == 307 {
// Parse the updated location
respLoc, err := resp.Location()
if err != nil {
return err
}
// Ensure a protocol downgrade doesn't happen
if req.URL.Scheme == "https" && respLoc.Scheme != "https" {
return fmt.Errorf("redirect would cause protocol downgrade")
}
// Update the request
req.URL = respLoc
// Retry the request
resp, err = c.c.config.HttpClient.Do(req)
if err != nil {
return err
}
}
result = &Response{Response: resp}
if err := result.Error(); err != nil {
return err

View File

@ -2,6 +2,7 @@ package api
import (
"context"
"fmt"
"io"
"net/http"
@ -95,6 +96,29 @@ func (c *Sys) RaftSnapshot(snapWriter io.Writer) error {
return nil
}
// Check for a redirect, only allowing for a single redirect
if resp.StatusCode == 301 || resp.StatusCode == 302 || resp.StatusCode == 307 {
// Parse the updated location
respLoc, err := resp.Location()
if err != nil {
return err
}
// Ensure a protocol downgrade doesn't happen
if req.URL.Scheme == "https" && respLoc.Scheme != "https" {
return fmt.Errorf("redirect would cause protocol downgrade")
}
// Update the request
req.URL = respLoc
// Retry the request
resp, err = c.c.config.HttpClient.Do(req)
if err != nil {
return err
}
}
result = &Response{Response: resp}
if err := result.Error(); err != nil {
return err