* adding content-type to csv and json output (#336) * added to contributors and changelog * changed 'type' to 'content-type' * added content-type for html and md output * updated changelog Co-authored-by: layton <layton@desktop-manjaro.fritz.box> Co-authored-by: Joona Hoikkala <joohoi@users.noreply.github.com>
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package ffuf
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
}
|