added flush and content-length to stream