HTTP protocol handling code taken from the CherryPy wsgi server. Refactored to fit my coroutine architecture.