Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5437f8b

Browse files
committed
Fix for an Issue #85
1 parent 4de83da commit 5437f8b

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

lib/request/basic.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from lib.core.common import extractErrorMessage
1717
from lib.core.common import extractRegexResult
18+
from lib.core.common import getPublicTypeMembers
1819
from lib.core.common import getUnicode
1920
from lib.core.common import readInput
2021
from lib.core.common import resetCookieJar
@@ -53,7 +54,27 @@ def forgeHeaders(items=None):
5354
headers = dict(conf.httpHeaders)
5455
headers.update(items or {})
5556

56-
headers = dict(("-".join(_.capitalize() for _ in key.split('-')), value) for (key, value) in headers.items())
57+
class _str(str):
58+
def capitalize(self):
59+
return _str(self)
60+
61+
def title(self):
62+
return _str(self)
63+
64+
_ = headers
65+
headers = {}
66+
for key, value in _.items():
67+
success = False
68+
if key.upper() not in (_.upper() for _ in getPublicTypeMembers(HTTP_HEADER, True)):
69+
try:
70+
headers[_str(key)] = value # dirty hack for http://bugs.python.org/issue12455
71+
except UnicodeEncodeError: # don't do the hack on non-ASCII header names (they have to be properly encoded later on)
72+
pass
73+
else:
74+
success = True
75+
if not success:
76+
key = '-'.join(_.capitalize() for _ in key.split('-'))
77+
headers[key] = value
5778

5879
if conf.cj:
5980
if HTTP_HEADER.COOKIE in headers:

0 commit comments

Comments
 (0)