Your fault is how you think about sockets:
socket.recv
will wait forever for data from clients
You don't need a loop here.
However, your requests will be limited by recv
param.
But if you want to allow any size request,
you should detect the end of data by HTTP specification.
For example, if you wait headers only, double linefeed will mean they ends.
And size of body(for POST method for example) should be passed with Content-length
header as I know.
You issue is same as in this question: link
And google for HTTP Specifications, if you want to make correct HTTP server.