Revision c032f34d

b/pithos/api/functions.py
47 47
    put_account_headers, get_container_headers, put_container_headers, get_object_headers, put_object_headers,
48 48
    update_manifest_meta, update_sharing_meta, update_public_meta, validate_modification_preconditions,
49 49
    validate_matching_preconditions, split_container_object_string, copy_or_move_object,
50
    get_int_parameter, get_content_length, get_content_range, raw_input_socket,
51
    socket_read_iterator, object_data_response, put_object_block, hashmap_hash, api_method)
50
    get_int_parameter, get_content_length, get_content_range, socket_read_iterator,
51
    object_data_response, put_object_block, hashmap_hash, api_method)
52 52
from pithos.backends import backend
53 53
from pithos.backends.base import NotAllowedError
54 54

  
......
706 706
    
707 707
    if request.serialization != 'text':
708 708
        data = ''
709
        sock = raw_input_socket(request)
710
        for block in socket_read_iterator(sock, content_length, backend.block_size):
709
        for block in socket_read_iterator(request, content_length, backend.block_size):
711 710
            data = '%s%s' % (data, block)
712 711
        
713 712
        if request.serialization == 'json':
......
737 736
        md5 = hashlib.md5()
738 737
        size = 0
739 738
        hashmap = []
740
        sock = raw_input_socket(request)
741
        for data in socket_read_iterator(sock, content_length, backend.block_size):
739
        for data in socket_read_iterator(request, content_length, backend.block_size):
742 740
            # TODO: Raise 408 (Request Timeout) if this takes too long.
743 741
            # TODO: Raise 499 (Client Disconnect) if a length is defined and we stop before getting this much data.
744 742
            size += len(data)
......
1022 1020
                length -= bytes
1023 1021
                sbi += 1
1024 1022
    else:
1025
        sock = raw_input_socket(request)
1026 1023
        data = ''
1027
        for d in socket_read_iterator(sock, length, backend.block_size):
1024
        for d in socket_read_iterator(request, length, backend.block_size):
1028 1025
            # TODO: Raise 408 (Request Timeout) if this takes too long.
1029 1026
            # TODO: Raise 499 (Client Disconnect) if a length is defined and we stop before getting this much data.
1030 1027
            data += d
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