From fb770852e87d97196e31f27c33ee8eee89aecc27 Mon Sep 17 00:00:00 2001 From: arijitchakraborty Date: Mon, 22 Jul 2013 19:41:01 +0530 Subject: [PATCH] Skipping cookie retrieval for non http requests --- scrapy/http/cookies.py | 2 ++ scrapy/tests/test_downloadermiddleware_cookies.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/scrapy/http/cookies.py b/scrapy/http/cookies.py index c137d5ad1..cc96cf8ac 100644 --- a/scrapy/http/cookies.py +++ b/scrapy/http/cookies.py @@ -23,6 +23,8 @@ class CookieJar(object): # the cookiejar implementation iterates through all domains # instead we restrict to potential matches on the domain req_host = urlparse_cached(request).hostname + if not req_host: + return if not IPV4_RE.search(req_host): hosts = potential_domain_matches(req_host) diff --git a/scrapy/tests/test_downloadermiddleware_cookies.py b/scrapy/tests/test_downloadermiddleware_cookies.py index 19c720a75..5f5e7a3d5 100644 --- a/scrapy/tests/test_downloadermiddleware_cookies.py +++ b/scrapy/tests/test_downloadermiddleware_cookies.py @@ -129,3 +129,8 @@ class CookiesMiddlewareTest(TestCase): req5_3 = Request('http://scrapytest.org/some-redirected-path') assert self.mw.process_request(req5_3, self.spider) is None self.assertEquals(req5_3.headers.get('Cookie'), 'C1=value1') + + #skip cookie retrieval for not http request + req6 = Request('file:///scrapy/sometempfile') + assert self.mw.process_request(req6, self.spider) is None + self.assertEquals(req6.headers.get('Cookie'), None)