Spent a day on this, I have tried going back to 1.93 and 1.92 and the results are identical.
It appears that the socket is only accepting 3 connections, and any requests that exceed 3 that are made by chrome (or firefox or safari) browser are dropped by the socket rather than queued, despite the fact that listen() is set for 5 connections which is the max.
I have also tried reducing this to 4,3,2 and 1 but the behavior is identical.
In the html page, there are 4 files (5 including the actual index.htm page) that are loaded in the header:
Code: Select all
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" type="text/css" href="css/tabs.css">
<link rel="stylesheet" type="text/css" href="css/xtabs.css">
<script type="text/javascript" src="js/index.js"></script>
Only index.htm, index.css and tabs.css ever get loaded, chrome reports that xtabs.css and index.js as:
I have logged the reading of each line immediatly after accept(), and it only ever shows the first 3 connections, there is no sign of the request for the other files ever reaching the accept():
HTTP serve on IP: 192.168.0.113 PORT: 80
Code: Select all
b'Host: 192.168.0.113\r\n'
b'Connection: keep-alive\r\n'
b'Cache-Control: max-age=0\r\n'
b'Upgrade-Insecure-Requests: 1\r\n'
b'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36\r\n'
b'Sec-Metadata: cause="forced", destination="document", site="cross-site"\r\n'
b'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n'
b'Accept-Encoding: gzip, deflate\r\n'
b'Accept-Language: en-GB,en;q=0.9,en-US;q=0.8,pl;q=0.7,la;q=0.6\r\n'
b'\r\n'
b'Host: 192.168.0.113\r\n'
b'Connection: keep-alive\r\n'
b'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36\r\n'
b'Sec-Metadata: destination=style, site=same-origin\r\n'
b'Accept: text/css,*/*;q=0.1\r\n'
b'Referer: http://192.168.0.113/\r\n'
b'Accept-Encoding: gzip, deflate\r\n'
b'Accept-Language: en-GB,en;q=0.9,en-US;q=0.8,pl;q=0.7,la;q=0.6\r\n'
b'\r\n'
b'Host: 192.168.0.113\r\n'
b'Connection: keep-alive\r\n'
b'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36\r\n'
b'Sec-Metadata: destination=style, site=same-origin\r\n'
b'Accept: text/css,*/*;q=0.1\r\n'
b'Referer: http://192.168.0.113/\r\n'
b'Accept-Encoding: gzip, deflate\r\n'
b'Accept-Language: en-GB,en;q=0.9,en-US;q=0.8,pl;q=0.7,la;q=0.6\r\n'
b'\r\n'
And this is the main code that handles the requests:
Code: Select all
self.optimise = True
while True:
print('HTTP serve on IP:', wlan.net.ifconfig()[0],'PORT:', self.port )
self.sock = socket.socket()
ai = socket.getaddrinfo("0.0.0.0", self.port)
addr = ai[0][-1]
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(addr)
self.sock.listen(5)
while True:
bits = self.sock.accept()
req = {
"sock": bits[0],
"addr": bits[1],
"head": [],
"path": None
}
if not self.optimise:
res = req['sock'].makefile("rwb")
else:
res = req['sock']
req['get'] = res.readline().decode('UTF-8').rstrip();
while True:
h = res.readline()
print(h)
if h == b"" or h == b"\r\n":
break
else:
req['head'].append(h.decode('UTF-8').rstrip())
self.request(req,res)
if not self.optimise:
req['sock'].close()
req = None
res = None
gc.collect()