mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-10 15:44:45 +00:00
Merge pull request #133 from linkcheck/fix-cookies-harder
Load cookies from the --cookiefile correctly
This commit is contained in:
commit
54e7326835
4 changed files with 14 additions and 4 deletions
|
|
@ -42,12 +42,12 @@ def from_file (filename):
|
|||
line = line.rstrip()
|
||||
if not line:
|
||||
if lines:
|
||||
entries.append(from_headers("\r\n".join(lines)))
|
||||
entries.extend(from_headers("\r\n".join(lines)))
|
||||
lines = []
|
||||
else:
|
||||
lines.append(line)
|
||||
if lines:
|
||||
entries.append(from_headers("\r\n".join(lines)))
|
||||
entries.extend(from_headers("\r\n".join(lines)))
|
||||
return entries
|
||||
|
||||
|
||||
|
|
@ -63,7 +63,9 @@ def from_headers (strheader):
|
|||
if "Host" not in headers:
|
||||
raise ValueError("Required header 'Host:' missing")
|
||||
host = headers["Host"]
|
||||
path= headers.get("Path", "/")
|
||||
# XXX: our --help says we also pay attention to the Scheme: header,
|
||||
# but we don't?!
|
||||
path = headers.get("Path", "/")
|
||||
for header in headers.getallmatchingheaders("Set-Cookie"):
|
||||
headervalue = header.split(':', 1)[1]
|
||||
for pairs in split_header_words([headervalue]):
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ def new_request_session(config, cookies):
|
|||
})
|
||||
if config["cookiefile"]:
|
||||
for cookie in from_file(config["cookiefile"]):
|
||||
session.cookies = requests.cookies.merge_cookies(session.cookies, cookie)
|
||||
session.cookies.set_cookie(cookie)
|
||||
return session
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
Host: example.org
|
||||
Path: /hello
|
||||
Set-cookie: om="nomnom"
|
||||
|
||||
Host: example.com
|
||||
Set-cookie: multiple=cookies
|
||||
Set-cookie: are=allowed
|
||||
|
|
|
|||
|
|
@ -72,8 +72,12 @@ class TestCookies (unittest.TestCase):
|
|||
self.assertRaises(ValueError, from_headers, "\r\n".join(lines))
|
||||
|
||||
def test_cookie_file (self):
|
||||
# Regression test for https://github.com/linkcheck/linkchecker/issues/62
|
||||
config = linkcheck.configuration.Configuration()
|
||||
here = os.path.dirname(__file__)
|
||||
config['cookiefile'] = os.path.join(here, 'cookies.txt')
|
||||
aggregate = linkcheck.director.get_aggregate(config)
|
||||
aggregate.add_request_session()
|
||||
session = aggregate.get_request_session()
|
||||
self.assertEqual({c.name for c in session.cookies},
|
||||
{'om', 'multiple', 'are'})
|
||||
|
|
|
|||
Loading…
Reference in a new issue