Code cut & paste from the original server package. Cleaned up, you have only the HTTP specific part here, and it has to be optimized and enhanced.