Skip to content

Commit 82b187f

Browse files
committed
S3DownloadHandler: fix auth for requests with quoted paths/query params
1 parent 1b03b12 commit 82b187f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

scrapy/core/downloader/handlers/s3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from urlparse import unquote
2+
13
from scrapy import optional_features
24
from scrapy.exceptions import NotConfigured
35
from scrapy.utils.httpobj import urlparse_cached
@@ -54,8 +56,8 @@ def download_request(self, request, spider):
5456
signed_headers = self.conn.make_request(
5557
method=request.method,
5658
bucket=bucket,
57-
key=p.path,
58-
query_args=p.query,
59+
key=unquote(p.path),
60+
query_args=unquote(p.query),
5961
headers=request.headers,
6062
data=request.body)
6163
httpreq = request.replace(url=url, headers=signed_headers)

tests/test_downloader_handlers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ def test_request_signing6(self):
482482
self.assertEqual(httpreq.headers['Authorization'], \
483483
'AWS 0PN5J17HBGZHT7JJ3X82:C0FlOtU8Ylb9KDTpZqYkZPX91iI=')
484484

485+
def test_request_signing7(self):
486+
# ensure that spaces are quoted properly before signing
487+
req = Request(
488+
("s3://johnsmith/photos/my puppy.jpg"
489+
"?response-content-disposition=my puppy.jpg"),
490+
method='GET',
491+
headers={
492+
'Date': 'Tue, 27 Mar 2007 19:42:41 +0000',
493+
})
494+
httpreq = self.download_request(req, self.spider)
495+
self.assertEqual(
496+
httpreq.headers['Authorization'],
497+
'AWS 0PN5J17HBGZHT7JJ3X82:+CfvG8EZ3YccOrRVMXNaK2eKZmM=')
498+
499+
485500
class FTPTestCase(unittest.TestCase):
486501

487502
username = "scrapy"

0 commit comments

Comments
 (0)