refactored ws code out of http.c