This loop should be done only if we have  "Connection: Keep-Alive"

I don't see where it is checked.