mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
improve handleRedirect method, add debug output
This commit is contained in:
parent
5f73510679
commit
6db0373025
1 changed files with 10 additions and 6 deletions
|
@ -185,23 +185,27 @@ func handleRedirect(w *httptest.ResponseRecorder, req *http.Request) (int, *byte
|
|||
// Follow external redirect
|
||||
redirURL, err := w.Result().Location()
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("Invalid location header")
|
||||
return 0, nil, fmt.Errorf("invalid location header")
|
||||
}
|
||||
|
||||
// TODO: resend orginal request body
|
||||
req, err := http.NewRequest(req.Method, redirURL.String(), nil)
|
||||
log.Println("redirecting request to", redirURL.String())
|
||||
|
||||
req, err := http.NewRequest(req.Method, redirURL.String(), req.Body)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("Failed to create new request: %v", err)
|
||||
return 0, nil, fmt.Errorf("handle redirect: failed to create new request: %v", err)
|
||||
}
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("Failed to follow redirect: %v", err)
|
||||
return 0, nil, fmt.Errorf("handle redirect: failed to follow redirect: %v", err)
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(resp.Body)
|
||||
_, err = buf.ReadFrom(resp.Body)
|
||||
if err != nil {
|
||||
return 0, nil, fmt.Errorf("handle redirect: failed to follow redirect: %v", err)
|
||||
}
|
||||
|
||||
return resp.StatusCode, buf, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue