Permalink
Browse files

Merge pull request #1 from jwiegley/master

Fixed a few issues I ran into trying to use mock-s3 for a project
  • Loading branch information...
Joe Server
Joe Server committed Jan 7, 2013
2 parents 33dcb3e + 514d680 commit 0eba9c8fb4758f93efb172202d99de47f79f913a
Showing with 19 additions and 2 deletions.
  1. +12 −1 actions.py
  2. +7 −1 file_store.py
View
@@ -1,4 +1,5 @@
import urllib2
+import datetime
def list_buckets(handler):
@@ -63,9 +64,18 @@ def get_item(handler, bucket_name, item_name):
headers = {}
for key in handler.headers:
headers[key.lower()] = handler.headers[key]
+
+ if hasattr(item, 'creation_date'):
+ last_modified = item.creation_date
+ else:
+ last_modified = item.modified_date
+ last_modified = datetime.datetime.strptime(last_modified, '%Y-%m-%dT%H:%M:%S.000Z')
+ last_modified = last_modified.strftime('%a, %d %b %Y %H:%M:%S GMT')
+
if 'range' in headers:
handler.send_response(206)
handler.send_header('Content-Type', item.content_type)
+ handler.send_header('Last-Modified', last_modified)
handler.send_header('Etag', item.md5)
handler.send_header('Accept-Ranges', 'bytes')
range = handler.headers['bytes'].split('=')[1]
@@ -81,9 +91,10 @@ def get_item(handler, bucket_name, item_name):
return
handler.send_response(200)
- handler.send_header('Content-Type', item.content_type)
+ handler.send_header('Last-Modified', last_modified)
handler.send_header('Etag', item.md5)
handler.send_header('Accept-Ranges', 'bytes')
+ handler.send_header('Content-Type', item.content_type)
handler.send_header('Content-Length', content_length)
handler.end_headers()
if handler.command == 'GET':
View
@@ -37,7 +37,9 @@ def create_bucket(self, bucket_name):
if bucket_name not in [bucket.name for bucket in self.buckets]:
creation_date = datetime.now().strftime('%Y-%m-%dT%H:%M:%S.000Z')
self.redis.sadd(BUCKETS_KEY, '%s|%s' % (bucket_name, creation_date))
- os.makedirs(os.path.join(self.root, bucket_name))
+ target = os.path.join(self.root, bucket_name)
+ if not os.path.isdir(target):
+ os.makedirs(target)
bucket = Bucket(bucket_name, creation_date)
self.buckets.append(bucket)
else:
@@ -120,6 +122,8 @@ def store_data(self, bucket, item_name, headers, data):
for key in headers:
lower_headers[key.lower()] = headers[key]
headers = lower_headers
+ if 'content-type' not in headers:
+ headers['content-type'] = 'application/octet-stream'
size = int(headers['content-length'])
m.update(data)
@@ -161,6 +165,8 @@ def store_item(self, bucket, item_name, handler):
headers = {}
for key in handler.headers:
headers[key.lower()] = handler.headers[key]
+ if 'content-type' not in headers:
+ headers['content-type'] = 'application/octet-stream'
size = int(headers['content-length'])
data = handler.rfile.read(size)

0 comments on commit 0eba9c8

Please sign in to comment.