Skip to content

Commit 2080fca

Browse files
committed
1 parent f488377 commit 2080fca

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3285,7 +3285,7 @@ def __init__(self):
32853285
pointer = pointer.next[char]
32863286
pointer.current.append(option)
32873287

3288-
for mnemonic in mnemonics.split(','):
3288+
for mnemonic in (mnemonics or "").split(','):
32893289
found = None
32903290
name = mnemonic.split('=')[0].replace("-", "").strip()
32913291
value = mnemonic.split('=')[1] if len(mnemonic.split('=')) > 1 else None

lib/core/option.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,9 @@ def _setHTTPExtraHeaders():
13391339
conf.headers = conf.headers.split("\n") if "\n" in conf.headers else conf.headers.split("\\n")
13401340

13411341
for headerValue in conf.headers:
1342+
if not headerValue.strip():
1343+
continue
1344+
13421345
if headerValue.count(':') >= 1:
13431346
header, value = (_.lstrip() for _ in headerValue.split(":", 1))
13441347

lib/parse/cmdline.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def cmdLineParser():
114114
action="store_true",
115115
help="Ignore Set-Cookie header from response")
116116

117-
request.add_option("-H", "--user-agent", dest="agent",
117+
request.add_option("--user-agent", dest="agent",
118118
help="HTTP User-Agent header value")
119119

120120
request.add_option("--random-agent", dest="randomAgent",
@@ -127,6 +127,9 @@ def cmdLineParser():
127127
request.add_option("--referer", dest="referer",
128128
help="HTTP Referer header value")
129129

130+
request.add_option("-H", "--header", dest="header",
131+
help="Extra header (e.g. \"X-Forwarded-For: 127.0.0.1\")")
132+
130133
request.add_option("--headers", dest="headers",
131134
help="Extra headers (e.g. \"Accept-Language: fr\\nETag: 123\")")
132135

@@ -799,6 +802,7 @@ def _(self, *args):
799802
argv = []
800803
prompt = False
801804
advancedHelp = True
805+
extraHeaders = []
802806

803807
for arg in sys.argv:
804808
argv.append(getUnicode(arg, encoding=sys.getfilesystemencoding()))
@@ -860,6 +864,9 @@ def _(self, *args):
860864
for i in xrange(len(argv)):
861865
if argv[i] == "-hh":
862866
argv[i] = "-h"
867+
elif argv[i] == "-H":
868+
if i + 1 < len(argv):
869+
extraHeaders.append(argv[i + 1])
863870
elif re.match(r"\A\d+!\Z", argv[i]) and argv[max(0, i - 1)] == "--threads" or re.match(r"\A--threads.+\d+!\Z", argv[i]):
864871
argv[i] = argv[i][:-1]
865872
conf.skipThreadCheck = True
@@ -888,6 +895,12 @@ def _(self, *args):
888895
print "\n[!] to see full list of options run with '-hh'"
889896
raise
890897

898+
if extraHeaders:
899+
if not args.headers:
900+
args.headers = ""
901+
delimiter = "\\n" if "\\n" in args.headers else "\n"
902+
args.headers += delimiter + delimiter.join(extraHeaders)
903+
891904
# Expand given mnemonic options (e.g. -z "ign,flu,bat")
892905
for i in xrange(len(argv) - 1):
893906
if argv[i] == "-z":

0 commit comments

Comments
 (0)