优化content-length输出, 现在超过max的结果也会正确的获取, 但添加了(exceed)标记

This commit is contained in:
M09Ic 2023-01-04 11:31:31 +08:00
parent f30712bb7e
commit 5dc8f7107f
2 changed files with 39 additions and 29 deletions

View File

@ -92,6 +92,9 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) {
} }
} }
if bl.BodyLength > ihttp.DefaultMaxBodySize {
bl.ExceedLength = true
}
bl.Source = int(unit.source) bl.Source = int(unit.source)
bl.ReqDepth = unit.depth bl.ReqDepth = unit.depth
bl.Spended = time.Since(start).Milliseconds() bl.Spended = time.Since(start).Milliseconds()

View File

@ -28,7 +28,7 @@ func NewBaseline(u, host string, resp *ihttp.Response) *Baseline {
bl.Host = host bl.Host = host
} }
bl.Body = resp.Body() bl.Body = resp.Body()
bl.BodyLength = len(bl.Body) bl.BodyLength = resp.ContentLength()
bl.Header = resp.Header() bl.Header = resp.Header()
bl.HeaderLength = len(bl.Header) bl.HeaderLength = len(bl.Header)
bl.RedirectURL = resp.GetHeader("Location") bl.RedirectURL = resp.GetHeader("Location")
@ -55,7 +55,7 @@ func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Ba
} }
bl.Body = resp.Body() bl.Body = resp.Body()
bl.BodyLength = len(bl.Body) bl.BodyLength = resp.ContentLength()
bl.Header = resp.Header() bl.Header = resp.Header()
bl.HeaderLength = len(bl.Header) bl.HeaderLength = len(bl.Header)
bl.RedirectURL = string(resp.GetHeader("Location")) bl.RedirectURL = string(resp.GetHeader("Location"))
@ -64,33 +64,34 @@ func NewInvalidBaseline(u, host string, resp *ihttp.Response, reason string) *Ba
} }
type Baseline struct { type Baseline struct {
Number int `json:"number"` Number int `json:"number"`
Url *url.URL `json:"-"` Url *url.URL `json:"-"`
UrlString string `json:"url"` UrlString string `json:"url"`
Path string `json:"path"` Path string `json:"path"`
Host string `json:"host"` Host string `json:"host"`
Body []byte `json:"-"` Body []byte `json:"-"`
BodyLength int `json:"body_length"` BodyLength int `json:"body_length"`
Header []byte `json:"-"` ExceedLength bool `json:"-"`
Raw []byte `json:"-"` Header []byte `json:"-"`
HeaderLength int `json:"header_length"` Raw []byte `json:"-"`
RedirectURL string `json:"redirect_url,omitempty"` HeaderLength int `json:"header_length"`
FrontURL string `json:"front_url,omitempty"` RedirectURL string `json:"redirect_url,omitempty"`
Status int `json:"status"` FrontURL string `json:"front_url,omitempty"`
Spended int64 `json:"spend"` // 耗时, 毫秒 Status int `json:"status"`
Title string `json:"title"` Spended int64 `json:"spend"` // 耗时, 毫秒
Frameworks Frameworks `json:"frameworks"` Title string `json:"title"`
Extracteds Extracteds `json:"extracts"` Frameworks Frameworks `json:"frameworks"`
ErrString string `json:"error"` Extracteds Extracteds `json:"extracts"`
Reason string `json:"reason"` ErrString string `json:"error"`
IsValid bool `json:"valid"` Reason string `json:"reason"`
IsFuzzy bool `json:"fuzzy"` IsValid bool `json:"valid"`
URLs []string `json:"-"` IsFuzzy bool `json:"fuzzy"`
Source int `json:"source"` Source int `json:"source"`
RecuDepth int `json:"-"` ReqDepth int `json:"depth"`
ReqDepth int `json:"depth"` Recu bool `json:"-"`
Recu bool `json:"-"` RecuDepth int `json:"-"`
*parsers.Hashes URLs []string `json:"-"`
*parsers.Hashes `json:"hashes"`
} }
func (bl *Baseline) IsDir() bool { func (bl *Baseline) IsDir() bool {
@ -292,6 +293,9 @@ func (bl *Baseline) ColorString() string {
line.WriteString(logs.GreenBold(strconv.Itoa(bl.Status))) line.WriteString(logs.GreenBold(strconv.Itoa(bl.Status)))
line.WriteString(" - ") line.WriteString(" - ")
line.WriteString(logs.YellowBold(strconv.Itoa(bl.BodyLength))) line.WriteString(logs.YellowBold(strconv.Itoa(bl.BodyLength)))
if bl.ExceedLength {
line.WriteString(logs.Red("(exceed)"))
}
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.GreenLine(bl.Additional("title"))) line.WriteString(logs.GreenLine(bl.Additional("title")))
@ -339,6 +343,9 @@ func (bl *Baseline) String() string {
line.WriteString(strconv.Itoa(bl.Status)) line.WriteString(strconv.Itoa(bl.Status))
line.WriteString(" - ") line.WriteString(" - ")
line.WriteString(strconv.Itoa(bl.BodyLength)) line.WriteString(strconv.Itoa(bl.BodyLength))
if bl.ExceedLength {
line.WriteString("(exceed)")
}
line.WriteString(" - ") line.WriteString(" - ")
line.WriteString(strconv.Itoa(int(bl.Spended)) + "ms") line.WriteString(strconv.Itoa(int(bl.Spended)) + "ms")
line.WriteString(bl.Additional("title")) line.WriteString(bl.Additional("title"))