mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
cookie_rewriting: if domain is specified, apply cookie to coll root
rather than rewritten path.. needed in order for subdomain cookies to be detected properly
This commit is contained in:
parent
8c15ac16fd
commit
9b732def93
@ -19,10 +19,14 @@ class WbUrlCookieRewriter(object):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
for name, morsel in cookie.iteritems():
|
for name, morsel in cookie.iteritems():
|
||||||
|
# if domain set, no choice but to expand cookie path to root
|
||||||
if morsel.get('domain'):
|
if morsel.get('domain'):
|
||||||
del morsel['domain']
|
del morsel['domain']
|
||||||
if morsel.get('path'):
|
morsel['path'] = self.url_rewriter.prefix
|
||||||
|
# else set cookie to rewritten path
|
||||||
|
elif morsel.get('path'):
|
||||||
morsel['path'] = self.url_rewriter.rewrite(morsel['path'])
|
morsel['path'] = self.url_rewriter.rewrite(morsel['path'])
|
||||||
|
# remove expires as it refers to archived time
|
||||||
if morsel.get('expires'):
|
if morsel.get('expires'):
|
||||||
del morsel['expires']
|
del morsel['expires']
|
||||||
|
|
||||||
|
@ -3,12 +3,16 @@ r"""
|
|||||||
>>> rewrite_cookie('a=b; c=d;')
|
>>> rewrite_cookie('a=b; c=d;')
|
||||||
[('Set-Cookie', 'a=b'), ('Set-Cookie', 'c=d')]
|
[('Set-Cookie', 'a=b'), ('Set-Cookie', 'c=d')]
|
||||||
|
|
||||||
>>> rewrite_cookie('some=value; Domain=foo.com; Path=/;')
|
>>> rewrite_cookie('some=value; Path=/;')
|
||||||
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/')]
|
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/')]
|
||||||
|
|
||||||
>>> rewrite_cookie('some=value; Domain=foo.com; Path=/diff/path/;')
|
>>> rewrite_cookie('some=value; Path=/diff/path/;')
|
||||||
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/diff/path/')]
|
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/diff/path/')]
|
||||||
|
|
||||||
|
# if domain set, set path to root
|
||||||
|
>>> rewrite_cookie('some=value; Domain=.example.com; Path=/diff/path/;')
|
||||||
|
[('Set-Cookie', 'some=value; Path=/pywb/')]
|
||||||
|
|
||||||
>>> rewrite_cookie('abc=def; Path=file.html; Expires=Wed, 13 Jan 2021 22:23:01 GMT')
|
>>> rewrite_cookie('abc=def; Path=file.html; Expires=Wed, 13 Jan 2021 22:23:01 GMT')
|
||||||
[('Set-Cookie', 'abc=def; Path=/pywb/20131226101010/http://example.com/some/path/file.html')]
|
[('Set-Cookie', 'abc=def; Path=/pywb/20131226101010/http://example.com/some/path/file.html')]
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ HTTP Headers Rewriting
|
|||||||
'text_type': None}
|
'text_type': None}
|
||||||
|
|
||||||
# cookie, host/origin rewriting
|
# cookie, host/origin rewriting
|
||||||
>>> _test_headers([('Connection', 'close'), ('Set-Cookie', 'foo=bar; Path=/; Domain=.example.com, abc=def; Path=somefile.html'), ('Host', 'example.com'), ('Origin', 'https://example.com')])
|
>>> _test_headers([('Connection', 'close'), ('Set-Cookie', 'foo=bar; Path=/; abc=def; Path=somefile.html'), ('Host', 'example.com'), ('Origin', 'https://example.com')])
|
||||||
{'charset': None,
|
{'charset': None,
|
||||||
'removed_header_dict': {},
|
'removed_header_dict': {},
|
||||||
'status_headers': StatusAndHeaders(protocol = '', statusline = '200 OK', headers = [ ('X-Archive-Orig-Connection', 'close'),
|
'status_headers': StatusAndHeaders(protocol = '', statusline = '200 OK', headers = [ ('X-Archive-Orig-Connection', 'close'),
|
||||||
@ -44,7 +44,7 @@ HTTP Headers Rewriting
|
|||||||
'text_type': 'js'}
|
'text_type': 'js'}
|
||||||
|
|
||||||
# Binary -- transfer-encoding removed
|
# Binary -- transfer-encoding removed
|
||||||
>>> _test_headers([('Content-Length', '200000'), ('Content-Type', 'image/png'), ('Set-Cookie', 'foo=bar; Path=/; Domain=.example.com'), ('Content-Encoding', 'gzip'), ('Transfer-Encoding', 'chunked')])
|
>>> _test_headers([('Content-Length', '200000'), ('Content-Type', 'image/png'), ('Set-Cookie', 'foo=bar; Path=/;'), ('Content-Encoding', 'gzip'), ('Transfer-Encoding', 'chunked')])
|
||||||
{'charset': None,
|
{'charset': None,
|
||||||
'removed_header_dict': {'transfer-encoding': 'chunked'},
|
'removed_header_dict': {'transfer-encoding': 'chunked'},
|
||||||
'status_headers': StatusAndHeaders(protocol = '', statusline = '200 OK', headers = [ ('Content-Length', '200000'),
|
'status_headers': StatusAndHeaders(protocol = '', statusline = '200 OK', headers = [ ('Content-Length', '200000'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user