Revision c032f34d pithos/api/util.py
b/pithos/api/util.py | ||
---|---|---|
439 | 439 |
|
440 | 440 |
MAX_UPLOAD_SIZE = 10 * (1024 * 1024) # 10MB |
441 | 441 |
|
442 |
def socket_read_iterator(sock, length=0, blocksize=4096):
|
|
442 |
def socket_read_iterator(request, length=0, blocksize=4096):
|
|
443 | 443 |
"""Return a maximum of blocksize data read from the socket in each iteration. |
444 | 444 |
|
445 | 445 |
Read up to 'length'. If 'length' is negative, will attempt a chunked read. |
446 | 446 |
The maximum ammount of data read is controlled by MAX_UPLOAD_SIZE. |
447 | 447 |
""" |
448 | 448 |
|
449 |
sock = raw_input_socket(request) |
|
449 | 450 |
if length < 0: # Chunked transfers |
451 |
# Small version (server does the dechunking). |
|
452 |
if request.environ.get('mod_wsgi.input_chunked', None): |
|
453 |
while length < MAX_UPLOAD_SIZE: |
|
454 |
data = sock.read(blocksize) |
|
455 |
if data == '': |
|
456 |
return |
|
457 |
yield data |
|
458 |
raise BadRequest('Maximum size is reached') |
|
459 |
|
|
460 |
# Long version (do the dechunking). |
|
450 | 461 |
data = '' |
451 | 462 |
while length < MAX_UPLOAD_SIZE: |
452 | 463 |
# Get chunk size. |
Also available in: Unified diff