refactor(sarin): extract cookie header building into cookieHeaderValue

This commit is contained in:
aykhans committed 2026-09-18 22:39:56 +04:00
1 parent 8b6e88bb74
commit 6b03ba9579
1 file changed
+17 -12
+17 -12
View File
@@ -191,18 +191,7 @@ func applyRequestDataToFastHTTP(reqData *script.RequestData, req *fasthttp.Reque
}
if len(reqData.Cookies) > 0 {
var sb strings.Builder
for k, values := range reqData.Cookies {
for _, v := range values {
if sb.Len() > 0 {
sb.WriteString("; ")
}
sb.WriteString(k)
sb.WriteByte('=')
sb.WriteString(v)
}
}
req.Header.Add("Cookie", sb.String())
req.Header.Add("Cookie", cookieHeaderValue(reqData.Cookies))
}
if scheme == "https" {
@@ -210,6 +199,22 @@ func applyRequestDataToFastHTTP(reqData *script.RequestData, req *fasthttp.Reque
}
}
// 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 cookies {
for _, v := range values {
if sb.Len() > 0 {
sb.WriteString("; ")
}
sb.WriteString(k)
sb.WriteByte('=')
sb.WriteString(v)
}
}
return sb.String()
}
func NewMethodGeneratorFunc(localRand *rand.Rand, methods []string, lazyRoot func() *template.Template) (requestDataGenerator, bool) {
methodGenerator, isDynamic := buildStringSliceGenerator(localRand, methods, lazyRoot)