Skip to content

Commit

Permalink
extract update of cookie jar
Browse files Browse the repository at this point in the history
  • Loading branch information
rbarazzutti committed Aug 20, 2023
1 parent f0773c3 commit 0e51d99
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/webclientimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,7 @@ func (webClient *webClientImpl) DoMeasure(followRedirect bool) *HTTPMeasure {

req, _ := http.NewRequest(webClient.config.Method, webClient.config.Target, nil)

if webClient.httpClient.Jar == nil || !webClient.config.KeepCookies {
jar, _ := cookiejar.New(nil)
var cookies []*http.Cookie
for _, c := range webClient.config.Cookies {
cookies = append(cookies, &http.Cookie{Name: c.Name, Value: c.Value})
}

jar.SetCookies(webClient.url, cookies)
webClient.httpClient.Jar = jar
}
webClient.updateCookieJar()

req = req.WithContext(measureContext.ctx())

Expand Down Expand Up @@ -383,3 +374,16 @@ func (webClient *webClientImpl) moveToHttp3(altSvcH3 string, timerRegistry *stat
}
return webClient.DoMeasure(followRedirect)
}

func (webClient *webClientImpl) updateCookieJar() {
if webClient.httpClient.Jar == nil || !webClient.config.KeepCookies {
jar, _ := cookiejar.New(nil)
var cookies []*http.Cookie
for _, c := range webClient.config.Cookies {
cookies = append(cookies, &http.Cookie{Name: c.Name, Value: c.Value})
}

jar.SetCookies(webClient.url, cookies)
webClient.httpClient.Jar = jar
}
}

0 comments on commit 0e51d99

Please sign in to comment.