I'm trying to create a (very minimalist) web server with Python using the socket module. 
I have a problem with, I think, web browser caching.
Explanation:
When I load a page, the first time work. It will work 2-3 other time at the beginning, then it will load just one time every two requests made by my browser (I use Firefox). I press F5, it works, I re-press F5, it loads nothing infinitely, I re-press F5 and it works.
I looked at my python console, and it seems that Firefox doesn't send any request when the loading of the page fails. 
When I press Ctrl + F5, it ALWAYS work, Firefox send a request each time and my webserver send it the page. 
I tried adding HTTP headers to prevent caching (Cache-Control, Pragma, Expires), but it still works one in two. I tested with Internet Explorer, and it works better, but it sometime fails (on 4-5 requests, it will fail only one time).
So, my question is:
Why Firefox and IE sometimes doesn't send request and still seems to wait for something? What is the web server supposed to do?
Thanks.
This is not about caching. You don’t close the sockets after sending a response nor do you tell the browser that you don’t support multiple requests. So the browser will assume it can request again with the same connection.
Close the connection and if you claim to support HTTP 1.1 add an appropriate Connection header.
Also don’t bind/close the server socket after each request. There’s no need and it will just make things not work. Bind on startup, close on shutdown. 
The code might also fail on data that is non-ASCII since you tell the length of the string and not the actual data you send. These may be different.
Python/HTTP - How does web browsers cache work?