Skip to content

Commit f0e464f

Browse files
committed
Implement auto-referer option
The option -auto-referer, sets the referer HTTP header of the current request to it's URL.
1 parent 5f55bfa commit f0e464f

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

common/httpx/httpx.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ func (h *HTTPX) SetCustomHeaders(r *retryablehttp.Request, headers map[string]st
435435
userAgent := useragent.PickRandom()
436436
r.Header.Set("User-Agent", userAgent.Raw) //nolint
437437
}
438+
if h.Options.AutoReferer {
439+
r.Header.Set("Referer", r.URL.String())
440+
}
438441
}
439442

440443
func (httpx *HTTPX) setCustomCookies(req *http.Request) {

common/httpx/option.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
// Options contains configuration options for the client
1313
type Options struct {
1414
RandomAgent bool
15+
AutoReferer bool
1516
DefaultUserAgent string
1617
Proxy string
1718
// Deprecated: use Proxy

runner/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ type Options struct {
261261
ShowStatistics bool
262262
StatsInterval int
263263
RandomAgent bool
264+
AutoReferer bool
264265
StoreChain bool
265266
StoreVisionReconClusters bool
266267
Deny customlist.CustomList
@@ -484,6 +485,7 @@ func ParseOptions() *Options {
484485
flagSet.Var(&options.Deny, "deny", "denied list of IP/CIDR's to process (file or comma separated)"),
485486
flagSet.StringVarP(&options.SniName, "sni-name", "sni", "", "custom TLS SNI name"),
486487
flagSet.BoolVar(&options.RandomAgent, "random-agent", true, "enable Random User-Agent to use"),
488+
flagSet.BoolVar(&options.AutoReferer, "auto-referer", false, "set the Referer header to the current URL"),
487489
flagSet.VarP(&options.CustomHeaders, "header", "H", "custom http headers to send with request"),
488490
flagSet.StringVarP(&options.Proxy, "proxy", "http-proxy", "", "proxy (http|socks) to use (eg http://127.0.0.1:8080)"),
489491
flagSet.BoolVar(&options.Unsafe, "unsafe", false, "send raw requests skipping golang normalization"),

runner/runner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ func New(options *Options) (*Runner, error) {
168168
} else {
169169
httpxOptions.RandomAgent = options.RandomAgent
170170
}
171+
if options.CustomHeaders.Has("Referer:") {
172+
httpxOptions.AutoReferer = false
173+
} else {
174+
httpxOptions.AutoReferer = options.AutoReferer
175+
}
171176
httpxOptions.ZTLS = options.ZTLS
172177
httpxOptions.MaxResponseBodySizeToSave = int64(options.MaxResponseBodySizeToSave)
173178
httpxOptions.MaxResponseBodySizeToRead = int64(options.MaxResponseBodySizeToRead)

0 commit comments

Comments
 (0)