mirror of
https://github.com/chainreactors/spray.git
synced 2025-09-15 19:50:18 +00:00
优化baseline的性能与信息获取
This commit is contained in:
parent
4a1cb28bdd
commit
e3fc74e78d
@ -49,8 +49,8 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p, _ := ants.NewPoolWithFunc(config.Thread, pool.Invoke)
|
p, _ := ants.NewPoolWithFunc(config.Thread, pool.Invoke)
|
||||||
|
|
||||||
pool.reqPool = p
|
pool.reqPool = p
|
||||||
|
|
||||||
// 挂起一个异步的处理结果线程, 不干扰主线程的请求并发
|
// 挂起一个异步的处理结果线程, 不干扰主线程的请求并发
|
||||||
go func() {
|
go func() {
|
||||||
for bl := range pool.tempCh {
|
for bl := range pool.tempCh {
|
||||||
|
@ -55,14 +55,21 @@ func NewBaseline(u, host string, resp *ihttp.Response) *Baseline {
|
|||||||
if resp.ClientType == ihttp.STANDARD {
|
if resp.ClientType == ihttp.STANDARD {
|
||||||
bl.Host = host
|
bl.Host = host
|
||||||
}
|
}
|
||||||
|
header := resp.Header()
|
||||||
|
bl.Header = make([]byte, len(header))
|
||||||
|
copy(bl.Header, header)
|
||||||
|
bl.HeaderLength = len(bl.Header)
|
||||||
|
|
||||||
body := resp.Body()
|
body := resp.Body()
|
||||||
bl.Body = make([]byte, len(body))
|
bl.Body = make([]byte, len(body))
|
||||||
copy(bl.Body, body)
|
copy(bl.Body, body)
|
||||||
bl.BodyLength = resp.ContentLength()
|
bl.BodyLength = resp.ContentLength()
|
||||||
bl.Header = resp.Header()
|
if bl.BodyLength == -1 {
|
||||||
bl.HeaderLength = len(bl.Header)
|
bl.BodyLength = len(bl.Body)
|
||||||
bl.RedirectURL = resp.GetHeader("Location")
|
}
|
||||||
|
|
||||||
bl.Raw = append(bl.Header, bl.Body...)
|
bl.Raw = append(bl.Header, bl.Body...)
|
||||||
|
bl.RedirectURL = resp.GetHeader("Location")
|
||||||
return bl
|
return bl
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,12 +92,9 @@ func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Ba
|
|||||||
bl.Host = host
|
bl.Host = host
|
||||||
}
|
}
|
||||||
|
|
||||||
body := resp.Body()
|
// 无效数据也要读取body, 否则keep-alive不生效
|
||||||
bl.Body = make([]byte, len(body))
|
resp.Body()
|
||||||
copy(bl.Body, body)
|
|
||||||
bl.BodyLength = resp.ContentLength()
|
bl.BodyLength = resp.ContentLength()
|
||||||
bl.Header = resp.Header()
|
|
||||||
bl.HeaderLength = len(bl.Header)
|
|
||||||
bl.RedirectURL = string(resp.GetHeader("Location"))
|
bl.RedirectURL = string(resp.GetHeader("Location"))
|
||||||
|
|
||||||
return bl
|
return bl
|
||||||
@ -339,8 +343,8 @@ func (bl *Baseline) ColorString() string {
|
|||||||
}
|
}
|
||||||
line.WriteString(" - ")
|
line.WriteString(" - ")
|
||||||
line.WriteString(logs.YellowBold(strconv.Itoa(int(bl.Spended)) + "ms"))
|
line.WriteString(logs.YellowBold(strconv.Itoa(int(bl.Spended)) + "ms"))
|
||||||
|
line.WriteString(logs.YellowBold(" - " + GetSourceName(bl.Source)))
|
||||||
line.WriteString(logs.GreenLine(bl.Additional("title")))
|
line.WriteString(logs.GreenLine(bl.Additional("title")))
|
||||||
line.WriteString(logs.GreenLine(bl.Additional("source")))
|
|
||||||
line.WriteString(logs.Cyan(bl.Frameworks.String()))
|
line.WriteString(logs.Cyan(bl.Frameworks.String()))
|
||||||
line.WriteString(logs.Cyan(bl.Extracteds.String()))
|
line.WriteString(logs.Cyan(bl.Extracteds.String()))
|
||||||
if bl.RedirectURL != "" {
|
if bl.RedirectURL != "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user