Commit 9b0f780a authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

renamed some files

parent 1e301cb4
......@@ -76,7 +76,7 @@ test:
command: ['server', '/minio']
alias: minio
before_script:
- wget https://dl.min.io/client/mc/release/linux-amd64/mc -O /usr/bin/mc && chmod +x /usr/bin/mc
- wget -qO /usr/bin/mc https://dl.min.io/client/mc/release/linux-amd64/mc && chmod +x /usr/bin/mc
- mc alias set gitlab http://minio:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD}
- mc mb gitlab/${S3_BUCKET}
script:
......
......@@ -171,25 +171,37 @@ func TestEndpoint(router *gin.Engine, token string, url string,
req.Header.Set("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+token)
const maxRedirCount = 10
var redirCount int
for redirCount = 0; redirCount < maxRedirCount; redirCount++ {
router.ServeHTTP(w, req)
if w.Code == 301 || w.Code == 302 || w.Code == 307 || w.Code == 308 {
req.URL, err = w.Result().Location()
if err != nil {
return 0, nil, fmt.Errorf("Invalid location header")
}
} else {
break
router.ServeHTTP(w, req)
return handleRedirect(w, req)
}
func handleRedirect(w *httptest.ResponseRecorder, req *http.Request) (int, *bytes.Buffer, error) {
if w.Code == http.StatusMovedPermanently ||
w.Code == http.StatusFound ||
w.Code == http.StatusTemporaryRedirect ||
w.Code == http.StatusPermanentRedirect {
// Follow external redirect
var err error
req.URL, err = w.Result().Location()
if err != nil {
return 0, nil, fmt.Errorf("Invalid location header")
}
}
if redirCount == maxRedirCount {
return 0, nil, fmt.Errorf("Max redirection count exceeded")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return 0, nil, fmt.Errorf("Failed to follow redirect: %v", err)
}
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
return resp.StatusCode, buf, nil
}
// No redirect
return w.Code, w.Body, nil
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment