mirror of
https://github.com/projectdiscovery/httpx.git
synced 2024-11-24 13:14:01 +03:00
Impelmented an option to only follow redirects on the same host
This commit is contained in:
parent
f07165dcf9
commit
9c47cac15d
@ -26,6 +26,7 @@ func main() {
|
||||
httpxOptions.Timeout = time.Duration(options.Timeout) * time.Second
|
||||
httpxOptions.RetryMax = options.Retries
|
||||
httpxOptions.FollowRedirects = options.FollowRedirects
|
||||
httpxOptions.FollowHostRedirects = options.FollowHostRedirects
|
||||
|
||||
httpxOptions.CustomHeaders = make(map[string]string)
|
||||
for _, customHeader := range options.CustomHeaders {
|
||||
|
@ -36,6 +36,7 @@ type Options struct {
|
||||
Version bool
|
||||
Verbose bool
|
||||
NoColor bool
|
||||
FollowHostRedirects bool
|
||||
}
|
||||
|
||||
// ParseOptions parses the command line options for application
|
||||
@ -55,6 +56,7 @@ func ParseOptions() *Options {
|
||||
flag.BoolVar(&options.StoreResponse, "store-response", false, "Store Response as domain.txt")
|
||||
flag.StringVar(&options.StoreResponseDir, "store-response-dir", ".", "Store Response Directory (default current directory)")
|
||||
flag.BoolVar(&options.FollowRedirects, "follow-redirects", false, "Follow Redirects")
|
||||
flag.BoolVar(&options.FollowHostRedirects, "follow-host-redirects", false, "Only follow redirects on the same host")
|
||||
flag.StringVar(&options.HttpProxy, "http-proxy", "", "Http Proxy")
|
||||
flag.BoolVar(&options.JSONOutput, "json", false, "JSON Output")
|
||||
flag.StringVar(&options.InputFile, "l", "", "File containing domains")
|
||||
|
@ -24,6 +24,7 @@ type HTTPX struct {
|
||||
CustomHeaders map[string]string
|
||||
}
|
||||
|
||||
|
||||
// New httpx instance
|
||||
func New(options *Options) (*HTTPX, error) {
|
||||
httpx := &HTTPX{}
|
||||
@ -39,13 +40,29 @@ func New(options *Options) (*HTTPX, error) {
|
||||
retryablehttpOptions.RetryMax = httpx.Options.RetryMax
|
||||
|
||||
var redirectFunc = func(_ *http.Request, _ []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
return http.ErrUseLastResponse // Tell the http client to not follow redirect
|
||||
}
|
||||
|
||||
if httpx.Options.FollowRedirects {
|
||||
if httpx.Options.FollowRedirects{
|
||||
// Follow redirects
|
||||
redirectFunc = nil
|
||||
}
|
||||
|
||||
if httpx.Options.FollowHostRedirects{
|
||||
// Only follow redirects on the same host
|
||||
redirectFunc = func(redirectedRequest *http.Request, previousRequest []*http.Request) error { // timo
|
||||
// Check if we get a redirect to a differen host
|
||||
var newHost = redirectedRequest.URL.Host
|
||||
var oldHost = previousRequest[0].URL.Host
|
||||
if newHost != oldHost{
|
||||
return http.ErrUseLastResponse // Tell the http client to not follow redirect
|
||||
} else {
|
||||
// Go through with the redirect
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
DialContext: dialer,
|
||||
MaxIdleConnsPerHost: -1,
|
||||
|
@ -14,6 +14,7 @@ type Options struct {
|
||||
|
||||
CustomHeaders map[string]string
|
||||
FollowRedirects bool
|
||||
FollowHostRedirects bool
|
||||
DefaultUserAgent string
|
||||
|
||||
HttpProxy string
|
||||
|
Loading…
Reference in New Issue
Block a user