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
+12 -7
+12 -7
View File
@@ -191,8 +191,18 @@ func applyRequestDataToFastHTTP(reqData *script.RequestData, req *fasthttp.Reque
} }
if len(reqData.Cookies) > 0 { 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 var sb strings.Builder
for k, values := range reqData.Cookies { for k, values := range cookies {
for _, v := range values { for _, v := range values {
if sb.Len() > 0 { if sb.Len() > 0 {
sb.WriteString("; ") sb.WriteString("; ")
@@ -202,12 +212,7 @@ func applyRequestDataToFastHTTP(reqData *script.RequestData, req *fasthttp.Reque
sb.WriteString(v) sb.WriteString(v)
} }
} }
req.Header.Add("Cookie", sb.String()) return sb.String()
}
if scheme == "https" {
req.URI().SetScheme("https")
}
} }
func NewMethodGeneratorFunc(localRand *rand.Rand, methods []string, lazyRoot func() *template.Template) (requestDataGenerator, bool) { func NewMethodGeneratorFunc(localRand *rand.Rand, methods []string, lazyRoot func() *template.Template) (requestDataGenerator, bool) {