'This is the original read function from httplib with a minor
modification that allows me to check the size of the file being
fetched, and throw an exception in case it is too big.'

def _raw_read(self, amt=None):

    if (self.fp is None):
        return ''
    max_file_size = (cf.get('max_file_size') or None)
    if max_file_size:
        if (self.length > max_file_size):
            self.status = NO_CONTENT
            self.reason = 'No    Content'
            self.close()
            return ''
    if self.chunked:
        return self._read_chunked(amt)
    if (amt is None):
        if (self.length is None):
            s = self.fp.read()
        else:
            s = self._safe_read(self.length)
            self.length = 0
        self.close()
        return s
    if (self.length is not None):
        if (amt > self.length):
            amt = self.length
    s = self.fp.read(amt)
    if (self.length is not None):
        self.length -= len(s)
    return s
