mirror of
https://github.com/aykhans/sarin.git
synced 2026-10-17 22:53:52 +00:00
refactor(sarin): extract cookie header building into cookieHeaderValue
This commit is contained in:
1 file changed
+12
-7
@@ -191,8 +191,18 @@ func applyRequestDataToFastHTTP(reqData *script.RequestData, req *fasthttp.Reque
|
||||
}
|
||||
|
||||
if len(reqData.Cookies) > 0 {
|
||||
req.Header.Add("Cookie", cookieHeaderValue(reqData.Cookies))
|
||||
}
|
||||
|
||||
if scheme == "https" {
|
||||
req.URI().SetScheme("https")
|
||||
}
|
||||
}
|
||||
|
||||
// cookieHeaderValue joins cookies into a single Cookie header value ("a=1; b=2").
|
||||
func cookieHeaderValue(cookies map[string][]string) string {
|
||||
var sb strings.Builder
|
||||
for k, values := range reqData.Cookies {
|
||||
for k, values := range cookies {
|
||||
for _, v := range values {
|
||||
if sb.Len() > 0 {
|
||||
sb.WriteString("; ")
|
||||
@@ -202,12 +212,7 @@ func applyRequestDataToFastHTTP(reqData *script.RequestData, req *fasthttp.Reque
|
||||
sb.WriteString(v)
|
||||
}
|
||||
}
|
||||
req.Header.Add("Cookie", sb.String())
|
||||
}
|
||||
|
||||
if scheme == "https" {
|
||||
req.URI().SetScheme("https")
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func NewMethodGeneratorFunc(localRand *rand.Rand, methods []string, lazyRoot func() *template.Template) (requestDataGenerator, bool) {
|
||||
|
||||
Reference in new issue
Block a user