Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.

Commit 8897273

Browse files
committed
Support ":" in cookie key
可以在 Cookie Key 中使用冒号 > Cookie 标准禁止在Key中使用冒号,部分网站中会存在该情况
1 parent 909c6f2 commit 8897273

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

hackhttp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"""
7777

7878
__title__ = 'hackhttp'
79-
__version__ = '1.0.3'
79+
__version__ = '1.0.4'
8080
__build__ = 0x020700
8181
__author__ = 'BugScanTeam'
8282
__author_email__ = '[email protected]'

hackhttp/hackhttp.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import cookielib
1515
import copy
1616
import time
17+
import string
1718

1819

1920
class httpheader(mimetools.Message):
@@ -38,6 +39,27 @@ def get(self, key, d=None):
3839
return self.dict.get(key, d)
3940

4041

42+
class MorselHook(Cookie.Morsel):
43+
"""
44+
Support ":" in Cookie key.
45+
46+
>>> import inspect
47+
>>> (inspect.getargspec(MorselHook.set)[3])[0]
48+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'*+-.^_`|~:"
49+
>>> cookie = Cookie.SimpleCookie()
50+
>>> cookie.load("key:key=abc; key=val")
51+
>>> print cookie
52+
Set-Cookie: key=val;
53+
Set-Cookie: key:key=abc;
54+
"""
55+
def set(
56+
self, key, val, coded_val,
57+
LegalChars=Cookie._LegalChars + ':',
58+
idmap=string._idmap, translate=string.translate):
59+
return super(MorselHook, self).set(
60+
key, val, coded_val, LegalChars, idmap, translate)
61+
62+
4163
class httpconpool():
4264
# 创建的连接总数, key 为 conhash
4365
connected = {}
@@ -141,6 +163,7 @@ def __init__(self, conpool=None, cookie_str=None, throw_exception=True):
141163
self.conpool = httpconpool(10)
142164
else:
143165
self.conpool = conpool
166+
Cookie.Morsel = MorselHook
144167
self.initcookie = Cookie.SimpleCookie()
145168
if cookie_str:
146169
if not cookie_str.endswith(';'):

0 commit comments

Comments
 (0)