MCPcopy Create free account
hub / github.com/chainreactors/spray / Build

Method Build

core/ihttp/request.go:28–104  ·  view source on GitHub ↗

Build 根据配置构建Request对象. word 是当前迭代的字典词,用于替换所有字段中的 {{FUZZ}} 占位符.

(ctx context.Context, clientType int, base, path, host, word string)

Source from the content-addressed store, hash-verified

26// Build 根据配置构建Request对象.
27// word 是当前迭代的字典词,用于替换所有字段中的 {{FUZZ}} 占位符.
28func (rc *RequestConfig) Build(ctx context.Context, clientType int, base, path, host, word string) (*Request, error) {
29 fuzz := func(s string) string {
30 return strings.ReplaceAll(s, FuzzMarker, word)
31 }
32
33 // 使用配置的 Host 或传入的 host, 并替换 FUZZ
34 hostToUse := host
35 if rc.Host != "" {
36 hostToUse = fuzz(rc.Host)
37 }
38
39 // 使用配置的 Path 或传入的 path, 并替换 FUZZ
40 pathToUse := path
41 if rc.Path != "" {
42 pathToUse = fuzz(rc.Path)
43 }
44
45 // 构建完整的URL,使用 SafePath 避免 host + path 直接拼接
46 var fullURL string
47 if u, err := url.Parse(base); err == nil && u.Scheme != "" && u.Host != "" {
48 // 只有当pathToUse不为空时才修改路径,否则保留原始URL的路径
49 if pathToUse != "" {
50 u.Path = pkg.SafePath(pkg.Dir(u.Path), pathToUse)
51 }
52 if rc.RawQuery != "" {
53 u.RawQuery = fuzz(rc.RawQuery)
54 }
55 fullURL = u.String()
56 } else {
57 fullURL = base + pkg.SafePath("/", pathToUse)
58 }
59
60 // 替换 body 中的 FUZZ
61 body := rc.Body
62 if len(body) > 0 && strings.Contains(string(body), FuzzMarker) {
63 body = []byte(fuzz(string(body)))
64 }
65
66 var req *Request
67 var err error
68
69 if clientType == FAST {
70 fastReq := fasthttp.AcquireRequest()
71 fastReq.Header.SetMethod(rc.Method)
72 fastReq.SetRequestURI(fullURL)
73 if hostToUse != "" {
74 fastReq.SetHost(hostToUse)
75 }
76 if len(body) > 0 {
77 fastReq.SetBody(body)
78 }
79 req = &Request{FastRequest: fastReq, ClientType: FAST}
80 } else {
81 var bodyReader *strings.Reader
82 if len(body) > 0 {
83 bodyReader = strings.NewReader(string(body))
84 }
85 var httpReq *http.Request

Callers 12

TestBuild_FuzzInPathFunction · 0.95
TestBuild_FuzzInHostFunction · 0.95
TestBuild_FuzzInHeaderFunction · 0.95
TestBuild_FuzzInBodyFunction · 0.95
TestBuild_FuzzInQueryFunction · 0.95
TestBuild_NoFuzzFunction · 0.95
TestBuild_EmptyWordFunction · 0.95
invokeNoScopeMethod · 0.95
InvokeMethod · 0.95
invokeMethod · 0.80

Calls 4

setHeadersWithFuzzMethod · 0.95
SafePathFunction · 0.92
DirFunction · 0.92
StringMethod · 0.45

Tested by 9

TestBuild_FuzzInPathFunction · 0.76
TestBuild_FuzzInHostFunction · 0.76
TestBuild_FuzzInHeaderFunction · 0.76
TestBuild_FuzzInBodyFunction · 0.76
TestBuild_FuzzInQueryFunction · 0.76
TestBuild_NoFuzzFunction · 0.76
TestBuild_EmptyWordFunction · 0.76