Fixed a bug causing failed http reads by reordering the socket set-up.