Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-08-07 21:44:21 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-08-08 01:11:02 +0300
commite9a4602eb023d1db4c5a7b46b654a70e17fe022d (patch)
tree935d8eb12627758e1653ada82e89209d81bdde7a
parentdc2500d0a6e06b3e762902996867d70246173523 (diff)
fix: propagate context to sub requests
-rw-r--r--internal/artifact/artifact.go2
-rw-r--r--internal/auth/auth.go8
-rw-r--r--internal/httprange/resource.go6
3 files changed, 7 insertions, 9 deletions
diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go
index 64156589..bdde8864 100644
--- a/internal/artifact/artifact.go
+++ b/internal/artifact/artifact.go
@@ -77,7 +77,7 @@ func (a *Artifact) TryMakeRequest(host string, w http.ResponseWriter, r *http.Re
}
func (a *Artifact) makeRequest(w http.ResponseWriter, r *http.Request, reqURL *url.URL, token string, additionalHandler func(*http.Response) bool) {
- req, err := http.NewRequest("GET", reqURL.String(), nil)
+ req, err := http.NewRequestWithContext(r.Context(), "GET", reqURL.String(), nil)
if err != nil {
logging.LogRequest(r).WithError(err).Error(createArtifactRequestErrMsg)
errortracking.Capture(err, errortracking.WithRequest(r))
diff --git a/internal/auth/auth.go b/internal/auth/auth.go
index 7307d668..877d5163 100644
--- a/internal/auth/auth.go
+++ b/internal/auth/auth.go
@@ -185,7 +185,7 @@ func (a *Auth) checkAuthenticationResponse(session *sessions.Session, w http.Res
}
// Fetch access token with authorization code
- token, err := a.fetchAccessToken(decryptedCode)
+ token, err := a.fetchAccessToken(r.Context(), decryptedCode)
if err != nil {
// Fetching token not OK
logRequest(r).WithError(err).WithField(
@@ -374,13 +374,13 @@ func verifyCodeAndStateGiven(r *http.Request) bool {
return r.URL.Query().Get("code") != "" && r.URL.Query().Get("state") != ""
}
-func (a *Auth) fetchAccessToken(code string) (tokenResponse, error) {
+func (a *Auth) fetchAccessToken(ctx context.Context, code string) (tokenResponse, error) {
token := tokenResponse{}
// Prepare request
url := fmt.Sprintf(tokenURLTemplate, a.internalGitlabServer)
content := fmt.Sprintf(tokenContentTemplate, a.clientID, a.clientSecret, code, a.redirectURI)
- req, err := http.NewRequest("POST", url, strings.NewReader(content))
+ req, err := http.NewRequestWithContext(ctx, "POST", url, strings.NewReader(content))
if err != nil {
return token, err
@@ -494,7 +494,7 @@ func (a *Auth) checkAuthentication(w http.ResponseWriter, r *http.Request, domai
} else {
url = fmt.Sprintf(apiURLUserTemplate, a.internalGitlabServer)
}
- req, err := http.NewRequest("GET", url, nil)
+ req, err := http.NewRequestWithContext(r.Context(), "GET", url, nil)
if err != nil {
logRequest(r).WithError(err).Error(failAuthErrMsg)
diff --git a/internal/httprange/resource.go b/internal/httprange/resource.go
index 4ef5f0ea..5e61d3fb 100644
--- a/internal/httprange/resource.go
+++ b/internal/httprange/resource.go
@@ -53,7 +53,7 @@ func (r *Resource) setError(err error) {
}
func (r *Resource) Request() (*http.Request, error) {
- req, err := http.NewRequest("GET", r.URL(), nil)
+ req, err := http.NewRequestWithContext(context.Background(), "GET", r.URL(), nil)
if err != nil {
return nil, err
}
@@ -71,13 +71,11 @@ func (r *Resource) Request() (*http.Request, error) {
func NewResource(ctx context.Context, url string, httpClient *http.Client) (*Resource, error) {
// the `h.URL` is likely pre-signed URL or a file:// scheme that only supports GET requests
- req, err := http.NewRequest("GET", url, nil)
+ req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return nil, err
}
- req = req.WithContext(ctx)
-
// we fetch a single byte and ensure that range requests is additionally supported
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", 0, 0))