mirror of
https://github.com/aykhans/sarin.git
synced 2026-10-17 14:53:52 +00:00
refactor(sarin): extract cookie header building into cookieHeaderValue
This commit is contained in:
1 file changed
+17
-12
+17
-12
@@ -191,18 +191,7 @@ func applyRequestDataToFastHTTP(reqData *script.RequestData, req *fasthttp.Reque
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(reqData.Cookies) > 0 {
|
if len(reqData.Cookies) > 0 {
|
||||||
var sb strings.Builder
|
req.Header.Add("Cookie", cookieHeaderValue(reqData.Cookies))
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if scheme == "https" {
|
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) {
|
func NewMethodGeneratorFunc(localRand *rand.Rand, methods []string, lazyRoot func() *template.Template) (requestDataGenerator, bool) {
|
||||||
methodGenerator, isDynamic := buildStringSliceGenerator(localRand, methods, lazyRoot)
|
methodGenerator, isDynamic := buildStringSliceGenerator(localRand, methods, lazyRoot)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user