Implement auto-referer option

The option -auto-referer, sets the referer HTTP header
of the current request to it's URL.
This commit is contained in:
siamak a.m.o
2025-07-26 12:20:34 +03:30
parent 5f55bfaa82
commit f0e464f6ea
4 changed files with 11 additions and 0 deletions
+3
View File
@@ -435,6 +435,9 @@ func (h *HTTPX) SetCustomHeaders(r *retryablehttp.Request, headers map[string]st
userAgent := useragent.PickRandom()
r.Header.Set("User-Agent", userAgent.Raw) //nolint
}
if h.Options.AutoReferer {
r.Header.Set("Referer", r.URL.String())
}
}
func (httpx *HTTPX) setCustomCookies(req *http.Request) {
+1
View File
@@ -12,6 +12,7 @@ import (
// Options contains configuration options for the client
type Options struct {
RandomAgent bool
AutoReferer bool
DefaultUserAgent string
Proxy string
// Deprecated: use Proxy
+2
View File
@@ -261,6 +261,7 @@ type Options struct {
ShowStatistics bool
StatsInterval int
RandomAgent bool
AutoReferer bool
StoreChain bool
StoreVisionReconClusters bool
Deny customlist.CustomList
@@ -484,6 +485,7 @@ func ParseOptions() *Options {
flagSet.Var(&options.Deny, "deny", "denied list of IP/CIDR's to process (file or comma separated)"),
flagSet.StringVarP(&options.SniName, "sni-name", "sni", "", "custom TLS SNI name"),
flagSet.BoolVar(&options.RandomAgent, "random-agent", true, "enable Random User-Agent to use"),
flagSet.BoolVar(&options.AutoReferer, "auto-referer", false, "set the Referer header to the current URL"),
flagSet.VarP(&options.CustomHeaders, "header", "H", "custom http headers to send with request"),
flagSet.StringVarP(&options.Proxy, "proxy", "http-proxy", "", "proxy (http|socks) to use (eg http://127.0.0.1:8080)"),
flagSet.BoolVar(&options.Unsafe, "unsafe", false, "send raw requests skipping golang normalization"),
+5
View File
@@ -168,6 +168,11 @@ func New(options *Options) (*Runner, error) {
} else {
httpxOptions.RandomAgent = options.RandomAgent
}
if options.CustomHeaders.Has("Referer:") {
httpxOptions.AutoReferer = false
} else {
httpxOptions.AutoReferer = options.AutoReferer
}
httpxOptions.ZTLS = options.ZTLS
httpxOptions.MaxResponseBodySizeToSave = int64(options.MaxResponseBodySizeToSave)
httpxOptions.MaxResponseBodySizeToRead = int64(options.MaxResponseBodySizeToRead)