Ejemplo n.º 1
0
def readResponseToFile(ssl_sock, targetFile):
	"""Call when a response is expected on a socket. Function waits for the entire header, 
	then keeps reading until the entire body has been read"""
	theBuf = socketBuffer.socketBuffer(ssl_sock)
	
	# We don't know in advance how big the header will be.
	buf = theBuf.read(1024)

	header, content_length, response = processResponse(buf)
	theBuf.putBack(response)
	response = ''

	dataWritten = 0
	f = open(targetFile, 'wb')

	DEBUG(header)
	DEBUG(content_length)

	if content_length == -1:
		# chunked
		readChunked(theBuf, f)
	else:
		while (dataWritten < content_length):
			toGo = content_length - dataWritten
			tmpBuf = theBuf.read(min(toGo, 1024))
			f.write(tmpBuf)
			dataWritten += len(tmpBuf)

	return header
Ejemplo n.º 2
0
def readResponse(ssl_sock):
	"""Call when a response is expected on a socket. Function waits for the entire header, 
	then keeps reading unti the entire body has been read"""
	theBuf = socketBuffer.socketBuffer(ssl_sock)
	
	# We don't know in advance how big the header will be.
	buf = theBuf.read(1024)

	header, content_length, response = processResponse(buf)
	theBuf.putBack(response)
	response = ''

	DEBUG(header)
	DEBUG(content_length)

	if content_length == -1:
		# chunked
		response = readChunked(theBuf)
	else:
		while (len(response) < content_length):
			response += theBuf.read(content_length - len(response))

	return header, response