parse http or smtp headers from a stream