Instead of having two versions of the socketHttpConnect function, I would prefer to have just one socketHttpConnect function and this check inside it.