# TODO
return s
-def add_auth_header(headers, method, path):
+def add_auth_headers(headers, method, path):
header_order = ['Content-Encoding', 'Content-Language', 'Content-Length',
'Content-MD5', 'Content-Type', 'Date', 'If-Modified-Since',
'If-Match', 'If-None-Match', 'If-Unmodified-Since',
signature = base64.b64encode(h.digest())
headers['Authorization'] = "SharedKey %s:%s" % (account_name, signature)
-def generate_request(path, method='GET', body="", headers={}):
- host = os.environ['AZURE_ACCOUNT_NAME'] + ".blob.core.windows.net"
- #auth_path = conn.calling_format.build_auth_path(self.bucket, key)
-
- headers = headers.copy()
- headers['Content-Length'] = str(len(body))
- if len(body) > 0:
- headers['Content-MD5'] = base64.b64encode(hashlib.md5(body).digest())
- add_auth_header(headers, method, path)
-
- req = "%s %s HTTP/1.1\r\nHost: %s\r\n" % (method, path, host)
- req = req + ''.join("%s: %s\r\n" % h for h in headers.items()) + "\r\n"
- print req
-
- conn = httplib.HTTPConnection(host)
- conn.request(method, path, body, headers)
- response = conn.getresponse()
- print "Response:", response.status
- print "Headers:", response.getheaders()
- print "Body:", response.read()
-
-if False:
- generate_request("/?comp=list")
+class Connection:
+ def __init__(self):
+ self.host = os.environ['AZURE_ACCOUNT_NAME'] + ".blob.core.windows.net"
+ self.conn = httplib.HTTPConnection(self.host)
+
+ def make_request(self, path, method='GET', body="", headers={}):
+ headers = headers.copy()
+ headers['Content-Length'] = str(len(body))
+ if len(body) > 0:
+ headers['Content-MD5'] \
+ = base64.b64encode(hashlib.md5(body).digest())
+ add_auth_headers(headers, method, path)
+
+ # req = "%s %s HTTP/1.1\r\nHost: %s\r\n" % (method, path, host)
+ # req = req + ''.join("%s: %s\r\n" % h for h in headers.items()) + "\r\n"
+ # print req
+
+ self.conn.request(method, path, body, headers)
+ response = self.conn.getresponse()
+ print "Response:", response.status
+ print "Headers:", response.getheaders()
+ print "Body:", response.read()
+
+if __name__ == '__main__':
+ # generate_request("/?comp=list")
+ buf = 'A' * 8192
+ conn = Connection()
+ for i in range(16):
+ conn.make_request('/benchmark/file-' + str(i), 'PUT', buf,
+ {'x-ms-blob-type': 'BlockBlob'})
+
+ for i in range(16):
+ conn.make_request('/benchmark/file-' + str(i), 'GET')