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

Commit

Permalink
Support ":" in cookie key
Browse files Browse the repository at this point in the history
可以在 Cookie Key 中使用冒号

> Cookie 标准禁止在Key中使用冒号,部分网站中会存在该情况
  • Loading branch information
Medicean committed Jun 6, 2016
1 parent 909c6f2 commit 8897273
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hackhttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"""

__title__ = 'hackhttp'
__version__ = '1.0.3'
__version__ = '1.0.4'
__build__ = 0x020700
__author__ = 'BugScanTeam'
__author_email__ = 'admin@bugscan.net'
Expand Down
23 changes: 23 additions & 0 deletions hackhttp/hackhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cookielib
import copy
import time
import string


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


class MorselHook(Cookie.Morsel):
"""
Support ":" in Cookie key.
>>> import inspect
>>> (inspect.getargspec(MorselHook.set)[3])[0]
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'*+-.^_`|~:"
>>> cookie = Cookie.SimpleCookie()
>>> cookie.load("key:key=abc; key=val")
>>> print cookie
Set-Cookie: key=val;
Set-Cookie: key:key=abc;
"""
def set(
self, key, val, coded_val,
LegalChars=Cookie._LegalChars + ':',
idmap=string._idmap, translate=string.translate):
return super(MorselHook, self).set(
key, val, coded_val, LegalChars, idmap, translate)


class httpconpool():
# 创建的连接总数, key 为 conhash
connected = {}
Expand Down Expand Up @@ -141,6 +163,7 @@ def __init__(self, conpool=None, cookie_str=None, throw_exception=True):
self.conpool = httpconpool(10)
else:
self.conpool = conpool
Cookie.Morsel = MorselHook
self.initcookie = Cookie.SimpleCookie()
if cookie_str:
if not cookie_str.endswith(';'):
Expand Down

0 comments on commit 8897273

Please sign in to comment.