Skip to content

Commit cdb9a0b

Browse files
immerrrdangra
authored andcommitted
S3DownloadHandler: fix auth for requests with quoted paths/query params
1 parent bb3a848 commit cdb9a0b

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)

scrapy/tests/test_downloader_handlers.py

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

382+
def test_request_signing7(self):
383+
# ensure that spaces are quoted properly before signing
384+
req = Request(
385+
("s3://johnsmith/photos/my puppy.jpg"
386+
"?response-content-disposition=my puppy.jpg"),
387+
method='GET',
388+
headers={
389+
'Date': 'Tue, 27 Mar 2007 19:42:41 +0000',
390+
})
391+
httpreq = self.download_request(req, self.spider)
392+
self.assertEqual(
393+
httpreq.headers['Authorization'],
394+
'AWS 0PN5J17HBGZHT7JJ3X82:+CfvG8EZ3YccOrRVMXNaK2eKZmM=')
395+
396+
382397
class FTPTestCase(unittest.TestCase):
383398

384399
username = "scrapy"

0 commit comments

Comments
 (0)