#! /usr/bin/env python
import pycurl, time, logging
began = time.time()
status = dict(sent=0)
total = 100*1024*1024
string1K = "."*1023+"\n"
assert len(string1K) == 1024
chunk = string1K*10

def read(size):
    print "req", size
    if status["sent"] >= total: return ""
    status["sent"] += len(chunk)
    return chunk

# Initialize pycurl
c = pycurl.Curl()
#c.setopt(pycurl.URL, "http://localhost:8080/foo")  # http
c.setopt(pycurl.URL, "https://localhost:8080/foo")  # https
c.setopt(pycurl.SSL_CIPHER_LIST, "ADH-AES128-SHA")
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.UPLOAD, 1)
c.setopt(pycurl.HTTPHEADER, ["Expect:"])
c.setopt(pycurl.INFILESIZE, total)
c.setopt(pycurl.READFUNCTION, read)

# Start transfer
started = time.time()
try: c.perform()
except: logging.exception("xx")
c.close()
finished = time.time()
print [began, started, finished]
