* Added response time reporting and filtering * Update to use the http config context * Added changelog and contributor info * Round time output in stdout to nearest millisecond * Change stdout duration rounding to use Milliseconds() * Go back to Round() for timing output * Changed stdout to display millisecond durations Co-authored-by: Joona Hoikkala <joohoi@users.noreply.github.com>
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package ffuf
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
// Response struct holds the meaningful data returned from request and is meant for passing to filters
|
|
type Response struct {
|
|
StatusCode int64
|
|
Headers map[string][]string
|
|
Data []byte
|
|
ContentLength int64
|
|
ContentWords int64
|
|
ContentLines int64
|
|
ContentType string
|
|
Cancelled bool
|
|
Request *Request
|
|
Raw string
|
|
ResultFile string
|
|
Time time.Duration
|
|
}
|
|
|
|
// GetRedirectLocation returns the redirect location for a 3xx redirect HTTP response
|
|
func (resp *Response) GetRedirectLocation(absolute bool) string {
|
|
|
|
redirectLocation := ""
|
|
if resp.StatusCode >= 300 && resp.StatusCode <= 399 {
|
|
if loc, ok := resp.Headers["Location"]; ok {
|
|
if len(loc) > 0 {
|
|
redirectLocation = loc[0]
|
|
}
|
|
}
|
|
}
|
|
|
|
if absolute {
|
|
redirectUrl, err := url.Parse(redirectLocation)
|
|
if err != nil {
|
|
return redirectLocation
|
|
}
|
|
baseUrl, err := url.Parse(resp.Request.Url)
|
|
if err != nil {
|
|
return redirectLocation
|
|
}
|
|
redirectLocation = baseUrl.ResolveReference(redirectUrl).String()
|
|
}
|
|
|
|
return redirectLocation
|
|
}
|
|
|
|
func NewResponse(httpresp *http.Response, req *Request) Response {
|
|
var resp Response
|
|
resp.Request = req
|
|
resp.StatusCode = int64(httpresp.StatusCode)
|
|
resp.ContentType = httpresp.Header.Get("Content-Type")
|
|
resp.Headers = httpresp.Header
|
|
resp.Cancelled = false
|
|
resp.Raw = ""
|
|
resp.ResultFile = ""
|
|
return resp
|
|
}
|