Skip to content

Commit

Permalink
Merge pull request #901 from niamster/i821
Browse files Browse the repository at this point in the history
s3: handle WebsiteRedirectLocation
  • Loading branch information
spulec committed Apr 16, 2017
2 parents 34c7111 + 6e61ee4 commit de28e7f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions moto/s3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, name, value, storage="STANDARD", etag=None, is_versioned=Fals
self.value = value
self.last_modified = datetime.datetime.utcnow()
self.acl = get_canned_acl('private')
self.website_redirect_location = None
self._storage_class = storage if storage else "STANDARD"
self._metadata = {}
self._expiry = None
Expand Down Expand Up @@ -103,6 +104,9 @@ def response_dict(self):
if self._is_versioned:
res['x-amz-version-id'] = str(self._version_id)

if self.website_redirect_location:
res['x-amz-website-redirect-location'] = self.website_redirect_location

return res

@property
Expand Down
1 change: 1 addition & 0 deletions moto/s3/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def _key_response_put(self, request, body, bucket_name, query, key_name, headers
metadata = metadata_from_headers(request.headers)
new_key.set_metadata(metadata)
new_key.set_acl(acl)
new_key.website_redirect_location = request.headers.get('x-amz-website-redirect-location')

template = self.response_template(S3_OBJECT_RESPONSE)
response_headers.update(new_key.response_dict)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_s3/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,19 @@ def test_boto3_key_etag():
resp = s3.get_object(Bucket='mybucket', Key='steve')
resp['ETag'].should.equal('"d32bda93738f7e03adb22e66c90fbc04"')

@mock_s3
def test_website_redirect_location():
s3 = boto3.client('s3', region_name='us-east-1')
s3.create_bucket(Bucket='mybucket')

s3.put_object(Bucket='mybucket', Key='steve', Body=b'is awesome')
resp = s3.get_object(Bucket='mybucket', Key='steve')
resp.get('WebsiteRedirectLocation').should.be.none

url = 'https://github.com/spulec/moto'
s3.put_object(Bucket='mybucket', Key='steve', Body=b'is awesome', WebsiteRedirectLocation=url)
resp = s3.get_object(Bucket='mybucket', Key='steve')
resp['WebsiteRedirectLocation'].should.equal(url)

@mock_s3
def test_boto3_list_keys_xml_escaped():
Expand Down

0 comments on commit de28e7f

Please sign in to comment.