mirror of
https://github.com/projectdiscovery/httpx
synced 2026-06-08 16:50:17 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user